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
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone
Accepted Solution

IllegalStateException in ListField

I am using ListField. and i am implementing ListFieldCallback for it.

Following code i am using. Its a thread which fetches data from web.And i draw data in drawListRow.

 

Thread t=new Thread(new Runnable()
{
public void run()
{
app.invokeLater(new Runnable()
{
public void run()
{
app.pushModalScreen(waitScreen);
}
});
InputStream ip= HttpUtils.getInputStream(url);
DataUtils dataUtils = new DataUtils();
if(!dataUtils.parseData(ip))
{
app.invokeLater(new Runnable()
{
public void run()
{
app.popScreen(waitScreen);
}
});
Status.show("Hey there is no network connection!!!");
return;
}
app.invokeLater(new Runnable()
{
public void run()
{
app.popScreen(waitScreen);
}
});
vector= dataUtils.getRegionItems();
if(vector==null)
{
Status.show("Something is not right here.\nPlease try again later.");
return;
}
ListCallBack callback = new ListCallBack();
lf.setCallback(callback);
lf.setRowHeight(100);
lf.setSize(vector.size());
vfm.add(lf);
return;
}
});
add(vfm);
t.start();

 

I debug the code. I am getting data in a vector vector. But unable to display it. Firstly it shows IllegalStateException.Then if i continue then it shows a blank screen. If i click somewhere in screen,it gets navigated to next screen. My goal is that i want Loading Popup until nand unless the data is fected and displayed. "waitScreen" is an instance of LoadingScreen class.

Please someone help. 

Please use plain text.
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: IllegalStateException in ListField

I am thinking status.show is the problem for that?

 

try to put status.show statements also in invokelater.

 

Thanks.

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: IllegalStateException in ListField

[ Edited ]

Thanks pradeep for reply. But i didnt get u. Will you please explain?

Please use plain text.
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: IllegalStateException in ListField

Hi Jovinz,

 

Try to debug it, when application stops with exception, try to find where it is showing the exception(green color background line). If it is not showing initially then you can find it by clicking next,next....line in debug stack.

 

If it is showing problem at status.show("message"), then put this block in app.invokelater.

Otherwise paste the code where you are getting then I can suggest.

 

Thanks.

Please use plain text.
Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780
My Carrier: Airtel

Re: IllegalStateException in ListField

What is your drawList method.

How you are using setData to your list.

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: IllegalStateException in ListField

In additon to Status.show causing a problem, following code will also fail:

 

For example:

vfm.add(lf);

 

Rather than running this with loads of invokelater, you would actually be better of running all of this in an invokeLater.  When you have got your head around how BlackBerry works, then try to optimise this and reduce the code that runs in the Event Thread. 

 

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: IllegalStateException in ListField

No issues with Status.show("message");
I think ListCallback is not getting called. Ther must must be some error at setsize of ListField. Bt i am getting data in vector.
Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: IllegalStateException in ListField

If you don't know how to use the debugger to track down problems like this, perhaps this will help:

http://supportforums.blackberry.com/t5/Java-Development/How-to-Debug-and-Optimize/ta-p/442791

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: IllegalStateException in ListField

Thanks for the suggestion. I have put whole thread inside one invokelater but my application hangs at waitscreen.
Can you please help me why my listfield is not getting displayed?
Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: IllegalStateException in ListField

public void drawListRow(final ListField list, final net.rim.device.api.ui.Graphics g, final int index, final int y, final int w)
{
RegionItem regionItem = (RegionItem)vector.elementAt(index);
g.drawText("Some text", 20, y, 0, w);
}

Please use plain text.