我使用J2ME在Eclipse中LWUIT發展S60。添加布局集裝箱環路觸發一個NullPointerException異常
我正在寫這個方法繪製列表項並嘗試手動創建列表而不是使用Lwuit列表。因爲正如我張貼在我最後一個問題here is LinK..不知道爲什麼,但它會降低性能。
所以在下面的方法我試圖創建在其中我添加添加兩個標籤到layoutX容器,並將Conatiner添加到layoutY容器並將該layoutY添加到BaseContainer,所以輸出看起來像列表。
方法是在這裏...
private void drawAgendasListItem(Vector vector) {
Container containerX[] = new Container[vector.size()];
Container containerY[] = new Container[vector.size()];
if (featuredeventsForm.contains(baseContainer)) {
baseContainer.removeAll();
featuredeventsForm.removeComponent(baseContainer);
System.out.println("base Container is removed ");
}
BoxLayout layoutX = new BoxLayout(BoxLayout.X_AXIS);
BoxLayout layoutY = new BoxLayout(BoxLayout.Y_AXIS);
for (int i = 0; i < vector.size(); i++) {
try {
containerX[i].setLayout(layoutX);
containerY[i].setLayout(layoutY);
Label startTime = new Label();
Label description = new Label();
startTime.getStyle().setBgTransparency(0);
startTime.setText("start 10:20 Am");
startTime.getStyle().setMargin(0, 0, 0, 5);
description.getStyle().setBgTransparency(0);
description.setText("decriptionString");
containerX[i].getStyle().setPadding(0, 0, 2, 2);
containerX[i].addComponent(startTime);
containerX[i].addComponent(description);
containerY[i].addComponent(containerX[i]);
baseContainer.addComponent(i, containerX[i]);
System.out.println("Component added to base Container @ " + i);
} catch (Exception e) {
System.out.println("Exception in drawAgendaListItem " + e);
}
}
featuredeventsForm.addComponent(baseContainer);
featuredeventsForm.invalidate();
featuredeventsForm.repaint();
System.out.println("All elements added and form repainted");
}
在上述方法中,當我嘗試分配佈局集裝箱它將觸發在行 containerX[i].setLayout(layoutX);
一個NullPointerException異常。
我不明白爲什麼會發生這種情況,我也嘗試對該行進行註釋,然後在行containerX[i].getStyle().setPadding(0, 0, 2, 2);
處觸發NullPointerException。
請幫忙....
好的,我想它。現在.. – MobileEvangelist 2012-07-13 10:14:14
我加了這幾行, containerX [i] = new Container(layoutX); containerY [i] = new Container(new BoxLayout(BoxLayout.Y_AXIS)); 但它仍然無法正常工作。同樣的錯誤火災 – MobileEvangelist 2012-07-13 10:25:24
我張貼在我最後一個問題列表呈現[這裏是LinK ..](http://stackoverflow.com/questions/11414861/in-listcellrenderer-getlistcellrenderercomponent-method-called-more-than-once ) – MobileEvangelist 2012-07-13 10:27:05