Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Jd007
Posts: 28
Registered: ‎02-13-2010
My Device: 9000
Accepted Solution

Weird Problem in ObjectListField

[ Edited ]

Hi all:

 

I experienced a pretty weird bug when trying out the BlackBerry Bold 9000 simulator. I had a custom class extending ObjectListField, and I wrote my own drawListRow(...) method. And since the data I'm displaying comes in a Vector, to initiate the Object[] needed to let the ObjectListField know how many items to draw, I use the following for the constructor:

 

public CustomObjectListField(Vector data) {
        this.set(new String[data.size()]);
}

 This code works perfectly fine in the BB 8330 simulator, which I've been using all along. The number of rows drawn is always correct, and there has been no issues at all. However when I switched to the BB Bold 9000 simulator today, the same code gave me a NullPointerException. I tried a few fixes, and the following worked:

 

public CustomObjectListField(Vector data) {
        String[] size = {"1", "2", ... };
        this.set(size);
}

Basically, manually, statically instantiate a String array works. But obviously I cannot predict the exact number of rows to draw each time, so this is not a permanent fix. I was wondering why the first constructor worked in the 8330 simulator but fails in the Bold 9000 simulator. Did RIM change the way Arrays are instantiated in the newer version of their OS?

 

Any suggestions/tips are welcome. Thanks to all in advance.

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Weird Problem in ObjectListField

you are aware of your first construct creating an empty array?

you could use Vector copyInto(Object[] anArray) to fill the array.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
Jd007
Posts: 28
Registered: ‎02-13-2010
My Device: 9000

Re: Weird Problem in ObjectListField

Yes I am aware that my first constructor creates an empty array, but because in my custom drawListRow method I'm reading data from the Vector, it worked fine in the 8330 simulator. The only job that the empty array does is to tell the ObjectListField how many rows to draw. So I'm still confused as to why the same code worked in the 8330 simulator but not in the Bold 9000 simulator.

 

Thanks for your solution, I'll try it out soon. 

Please use plain text.
Developer
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Weird Problem in ObjectListField

ok, you could also just call setSize

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
Jd007
Posts: 28
Registered: ‎02-13-2010
My Device: 9000

Re: Weird Problem in ObjectListField

Thank you very much, the Vector.copyInto(Object[] array) method worked. I tried the setSize() method but strangely it gave an ArrayIndexOutofBounds exception. 

Please use plain text.