1
我有黑莓水平和垂直現場經理的問題。在示例應用程序中,我將兩個垂直字段管理器添加到一個水平字段管理器中,GUI位於下圖中。黑莓現場管理器滾動顯示NullpointerException
在按鈕我卸下左側VFM領域變化監聽器,那麼只有Home鍵顯示,在home鍵收聽我加入左VFM,然後回到上面屏幕。
滾動左邊的內容並刪除左邊的VFM後出現問題,則只顯示主頁按鈕,並且導航欄(滾動)導致空指針異常屏幕。下圖包含錯誤的模擬器屏幕截圖。
這裏是再現錯誤的完整源代碼。
public class MyApp extends UiApplication{
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new MyScreen());
}
}
public final class MyScreen extends MainScreen{
private HorizontalFieldManager hfmMainManager = null;
private VerticalFieldManager menuButtonManager = null;
private String[] buttons = new String[]{"BUTTON ID 1",
"BUTTON ID 2",
"BUTTON ID 3",
"BUTTON ID 4",
"BUTTON ID 5",
"BUTTON ID 6",
"BUTTON ID 7",
"BUTTON ID 8",
"BUTTON ID 9",
"BUTTON ID 10"};
private boolean menuShowing = false;
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
super(Manager.NO_VERTICAL_SCROLL | MainScreen.NO_VERTICAL_SCROLLBAR
| Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR);
hfmMainManager = new HorizontalFieldManager(Manager.NO_HORIZONTAL_SCROLL
| Manager.NO_HORIZONTAL_SCROLLBAR);
////////////////////MENU BUTTONS
menuButtonManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);
menuButtonManager.add(new ButtonField("Header Button", Field.FIELD_HCENTER));
VerticalFieldManager vfmScrollable = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
for (int i = 0; i < buttons.length; i++) {
ButtonField buttonField = new ButtonField(buttons[i], Field.FIELD_HCENTER);
buttonField.setChangeListener(listenerButton);
vfmScrollable.add(buttonField);
}
menuButtonManager.add(vfmScrollable);
hfmMainManager.add(menuButtonManager);
VerticalFieldManager vfmMenuContentManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLLBAR | Manager.NO_VERTICAL_SCROLL);
ButtonField buttonField = new ButtonField("Home Button", Field.FIELD_HCENTER);
buttonField.setChangeListener(listenerButton);
buttonField.setMargin(10, 0, 10, 0);
vfmMenuContentManager.add(buttonField);
hfmMainManager.add(vfmMenuContentManager);
add(hfmMainManager);
menuShowing = true;
}
private FieldChangeListener listenerButton = new FieldChangeListener() {
public void fieldChanged(Field arg0, int arg1) {
synchronized (UiApplication.getEventLock()) {
if(menuShowing){
menuShowing = false;
hfmMainManager.delete(menuButtonManager);
}else{
menuShowing = true;
hfmMainManager.insert(menuButtonManager, 0);
}
}
}
};
}
我怎麼解決這個問題呢?
在此先感謝
問候
阿尼什
您好我已經更換同步(UiApplication.getEventLock())與UiApplication.getInstance()的invokeLater(Runnable的新{公共無效運行(){....但問題仍然存在。 – MobDev 2013-02-12 05:03:15