10-06-2010 01:06 PM - edited 10-06-2010 01:07 PM
Hi Blackberry Guys,
I am follwoing the Blackberry developers knowledge base artical How To - Create tabbed view screens
as an inspiration for my custom tab screen.
I have to create tab control with unlimited tabs as following
Tab1 | Tab2 | Tab3 | >>
On focusChanged of >>, I delete Tab1 from the horizontal manager, and add Tab4 and set the current focus to Tab4.
But when I invoke the tab4.setFocus(); it throws NullPointerException
Here is the focusChanged event for reference
public void focusChanged(Field field, int eventType)
if (eventType == FOCUS_GAINED)
(field == tabs[i])
tabPanel = getTabPanel(i);
if(field == LabelNext)
tabs[nextTab] = getNextTab();
Any idea of implementing Tab Screen with dynamic tabs would be be very much appriciated
Solved! Go to Solution.
10-06-2010 01:16 PM
Welcome to the forums!
Try wrapping setFocus() in invokeLater() - your focusChanged() is called inside a chain of calls surrounding a UI event. Let it (and the whole chain) finish then issue the setFocus().
Grabbing an event lock will not do any good - you are already on event thread in your focusChanged method. You really need to let the framework finish its job with the previous event before initiating a new one. That's why invokeLater() seems like the right way to go.
10-07-2010 04:29 AM - edited 10-07-2010 04:29 AM
Thanks for your suggestion Arkadyz
I still can't get it right. I am using invokeLater as below
public void run()
I get the NullPointerException.
Am I doing anything wrong with invokeLater?
10-07-2010 04:42 AM
Can you debug your code and find out what line gives you the exception, then examine the variables on that line and see which one is null?
10-07-2010 05:45 AM
The line below thows an exception.
I watched all values in the statement and none of them is null.
As maintaning the tab with >> & << becoming really complex and too many things to consider,
I am looking to display all labels on Horizontal Panel with Manager.HORIZONTAL_SCROLL and it works fine for me.
But I am sure that using invokeLater() with bit of testing shold work in this senario.