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
Developer
Posts: 23
Registered: ‎01-04-2009
My Device: Not Specified

ObjectListField.get() ClassCastException

[ Edited ]

if(!nameList.isEmpty()){
while(i < size){
currString = (String)callBack.get(nameList, i);
currString.trim();
if(name.compareTo(currString) < 0)
break;
i++;
}
}
callBack.insert(i, new LabelField(name));
nameList.setSize(size + 1);
nameList.setCallback(callBack);
updateDisplay();

 

This code sometimes throws an ClassCastException on

currString = (String)callBack.get(nameList, i);

nameList is my custom ListField class linked to an ObjectListField and filled with LabelField objects.  I would expect get() to return these LabelField objects but I was receiving the ClassCastException.  When I stored the result in an Object and used getClass() I saw that it was actually giving me back string objects.  This is fine except occasionally (and always when there is only one item in the list) get() will return a LabelField object instead of a String and throw the exception.  Is this a bug?

Message Edited by madoo14 on 01-09-2009 01:57 PM
BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: ObjectListField.get() ClassCastException

What BlackBerry model and handheld software version are you testing on?  You can find this under Options, About on the BlackBerry handheld.

 

As a work around, you could use the instanceof comparator to determine the class type of the object returned and then cast it appropriately.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 23
Registered: ‎01-04-2009
My Device: Not Specified

Re: ObjectListField.get() ClassCastException

I'm using the BlackBerry 8300 software version 4.5.0.44.  My work around was to simply catch the exception and then pull the text out of the label field object.
Highlighted
BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: ObjectListField.get() ClassCastException

I tried this with the a non custom ObjectListField and in each case, regardless of position, a LabelField was returned from the get method.  Are you able to reproduce this with a non customized field?  If not, how has your field been customized?  I recommend stepping through your custom code to see what may be happening there.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker