BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 04-01-2008, 02:08 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Big problem: ArrayIndexOutOfBoundsException !?!?!

Please Login to Remove!

I have made an application and have opened a new page that contains a lot of ui components i.e. about 50 - 60 ui components like label fields, text fields, number fields etc. So I build my application with net.rim library with JDE 4.2.0. When I run the application on 8120, 8300 and 8800 simulator it is running and everything is ok. When I tried to run it in 8100 simulator and 8100 handheld in this exact page it throws java.lang.ArrayIndexOutOfBoundsException. I tried so many possibilities to catch the exception. I just don't know where exactly it is thrown. In fact when i surround the code where it possibly crashes with try-catch the exception is not catched at all. But it just makes no sence because on the other simulators it has not crashed. Has someone had a problem like this ? I am very confused.

P.S. I am almost sure that i have not had a code where i pass over the size of an array. Otherwise it would not run on the 8120, 8300 or 8800 simulators. Thanks!
Offline  
Old 04-01-2008, 04:18 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: Airtel
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I guess, that components in the screen class are put in the stack to be shown on the BBscreen. So might be due to overflow of stack, u r getting such exception.

Try removing some components and execute.. wats the result.

If i m wrong in any thin please correct me.

Thanks.
Offline  
Old 04-01-2008, 05:01 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well in fact i tried this. Put in the stack 56 components but only label fields and it didn't throw the exception. If some of the components are edit fields, password fields, date fields etc. and even the number of the components is less than 56 it throws the exception. I am sorry, i had to add this information too in the first post.
Offline  
Old 04-01-2008, 05:05 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

One thing only if i add too many components it would throw StackOverflow error or something like this. But it didn't
Offline  
Old 04-01-2008, 06:22 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: Airtel
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you post your code, so that i can help you.
Offline  
Old 04-01-2008, 06:47 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
public class EditPage extends VerticalManager implements ContentManager, TrackwheelListener {
  private AccountImpl account;
  
  public EditPage(long style, AccountInfo accInfo) {
     super(style);
     account = new AccountImpl(accInfo);
     setContent(account.getFields());
  }
    
  /**
   * Sets the content of the page.
   */
  private void setContent(List fields) {
    FontFamily fontFamily[] = FontFamily.getFontFamilies();
    Font font = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 12);
    Font textFont = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 16);
    
    RulesManager rulesManager = new RulesManager(Manager.VERTICAL_SCROLL, 2 * fields.size());
    ComponentsFactory componentFactory = ComponentsFactory.getInstance();
    Field prevField = null;
    LabelField label;
    for (int i = 0; i < fields.size(); i++) {
      AccountFieldImpl accountField = (AccountFieldImpl) fields.get(i);
      String text = accountField.getName();
      label = new LabelField(text);
      label.setFont(font);
      Field valueField = componentFactory.getComponent(accountField.getType(), 
          contentWidth - font.getAdvance(text) - 21, 17, textFont);
      if (prevField == null) {
        rulesManager.add(label, 8, 8);
        rulesManager.add(valueField, XRule.PUT_AFTER, 5, label, 5);
      } else {
        rulesManager.add(label, 8, YRule.PUT_UNDER, 8, prevField);
        rulesManager.add(valueField, XRule.PUT_AFTER, 5, label, YRule.PUT_UNDER, 5, prevField);
      }
      prevField = label;
    }
    add(rulesManager);
  }
  
  /**
   * @see com.mycompany.ui.ContentManager#setThePosition(int, int)
   * 
   * @param x - int
   * @param y - int
   */
  public void setThePosition(int x, int y) {
    setPosition(x, y);
  }
  
  /**
   * @see com.mycompany.ui.ContentManager#setLayout(int, int)
   * 
   * @param width - int
   * @param height - int
   */
  public void setLayout(int width, int height) {
    super.sublayout(width, height);
  }

  /**
   * @see com.mycompany.ui.TrackwheelListener#trackwheelClick(int, int, Field)
   * 
   * @param status - int
   * @param time - int
   * @param field - Field
   */
  public boolean trackwheelClick(int status, int time, Field field) {
    return true;
  }
  
  /**
   * @see com.mycompany.ui.TrackwheelListener#trackwheelUnclick(int, int, Field)
   * 
   * @param status - int
   * @param time - int
   * @param field - Field
   */
  public boolean trackwheelUnclick(int status, int time, Field field) {
    return true;
  }
  
}
This is the UI page that is manager and holds all the ui field components. I have a class that is like custom manager to arrange the fields where i want. Here is a part of it:

Code:
public class RulesManager extends Manager {

  public static final int ALIGN_LEFT_TO = 0;
  public static final int ALIGN_RIGHT_TO = 1;
  public static final int ALIGN_VERTICAL_AXIS = 2;
  public static final int STICK_LEFT_TO = 3;
  public static final int STICK_RIGHT_TO = 4;
  public static final int ALIGN_UP_TO = 5;
  public static final int ALIGN_DOWN_TO = 6;
  public static final int ALIGN_HORIZONTAL_AXIS = 7;
  public static final int STICK_UP_TO = 8;
  public static final int STICK_DOWN_TO = 9;
  
  /** the width of the manager; always has the display width value */
  private int prefWidth;
  /** the height of the manager; depends on the number of fields and their position */
  private int prefHeight;
  /** contains all the fields holds by the manager packed by FieldData objects */
  private Vector fieldsData;

//........ some more methods

/**
   * Adds a field to this manager with x and y coordinates.
   * 
   * @param field - Field
   * @param x - int
   * @param y - int
   */
  public void add(Field field, int x, int y) {
    FieldData fd = new FieldData(field);
    fd.setXExact(x);
    fd.setYExact(y);
    add(field);
    prefHeight += field.getPreferredHeight() + y;
    fieldsData.addElement(fd);
  }
  
  /**
   * Adds a field to the manager.
   * 
   * @param newField - Field
   * @param xRule - XRule
   * @param xOffset - int
   * @param xrefField - Field
   * @param yRule - YRule
   * @param yOffset - int
   * @param yrefField - Field
   */
  public void add(Field newField, XRule xRule, int xOffset, Field xrefField, YRule yRule, int yOffset, Field yrefField) {
    validateNewFieldNull(newField);
    validateXRefField(newField, xrefField);
    validateYRefField(newField, yrefField);

    FieldData fd = new FieldData(newField);
    fd.setXRef(xrefField, xRule.getId(), xOffset);
    fd.setYRef(yrefField, yRule.getId(), yOffset);
    add(newField);
    fieldsData.addElement(fd);
  }

/**
   * @see net.rim.device.api.ui.Manager#sublayout(int, int)
   * 
   * @param width - int
   * @param height - int
   */
  public void sublayout(int width, int height) {
     int fieldsCount = fieldsData.size();
     for (int j = 0; j < fieldsCount; j++) {
        FieldData fieldData = (FieldData) fieldsData.elementAt(j);
        Field field = fieldData.getField();
        processRule(fieldData);
        setPositionChild(field, fieldData.getX(), fieldData.getY());
        layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight());
     }
     setExtent(width, prefHeight);
  }
I think it is a bit complicated to understand my code. But the problem is that this code works in 8120 simulator which is JDE 4.3.0, and not in 8100 (JDE 4.2.0)
Offline  
Old 04-01-2008, 07:45 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: Airtel
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are dealing with an array operation here:

Code:
 
FontFamily fontFamily[] = FontFamily.getFontFamilies();
    Font font = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 12);
    Font textFont = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 16);
Did you check whether FontFamily.getFontFamilies() method is returning more than 4 values.

As you are getting some values from the fontFamily[3].

Please check this case and let me know.
Offline  
Old 04-01-2008, 07:57 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The font families are 11. The problem is definitely not there. I think you can not help me, but thanks for the efforts !
Offline  
Old 04-03-2008, 06:23 AM   #9 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Location: india
Model: 8700
PIN: 12345
Carrier: Airtel
Posts: 62
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down I dont need message after run my application

I develop one third party application in blackberry 8700 device..in that application i get some values from mobile and transfer the values to the http url (it will done automatically inside the program) while transferring it i got a message (your information is transfered to this server)
did u allow or not..because i like to move this application as an enterprise application.publics not like the application..


wat can i do to avoid that..

Any one knows help me...

Thanks,
praveen
Offline  
Old 04-03-2008, 06:28 AM   #10 (permalink)
Grumpy Moderator
 
NJBlackBerry's Avatar
 
Join Date: Aug 2004
Location: Somewhere in the swamps of Jersey
Model: SGS7
Carrier: Verizon
Posts: 27,924
Post Thanks: 32
Thanked 463 Times in 399 Posts
Default

** DO NOT HIJACK OTHER PEOPLE'S THREADS **

Praveens - you have now posted your issue FOUR TIMES - that is three more than necessary.

Do not post your problem in someone else's thread. Simple forum etiquette.

Thank you.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.