創建JTabbedPane
並得到11的製表符數 之後的邏輯有什麼問題,然後使用setter?引用JTabbedPane的屬性時出現NullPointerException
我嘗試引用SetObjects.currentJTabbedPane
的tabCount
,它會拋出 NullPointerException
。
創建
jtp.setSelectedIndex(0);
int jtpCount=jtp.getTabCount();
System.out.println(C+M+AND+jtpCount+": jtpCount of The JTabbedPane created: \n");
setCurrentJTabbedPane(jtp);
int currentCount=SetObjects.currentJTabbedPane.getTabCount();
System.out.println(C+M+AND+currentCount+": currentCount for
SetObjects.currentJTabbedPane.getTabCount() : \n");
設定器
public static void setCurrentJTabbedPane(JTabbedPane currentJTabbedPane) {
String M =(" --> in setCurrentJTabbedPane() var: <-- \n");
System.out.println(M);
SetObjects.currentJTabbedPane = currentJTabbedPane;
System.out.println(C+M+AND+SetObjects.currentJTabbedPane.getTabCount()+":
SetObjects.currentJTabbedPane.getTabCount() : \n");
}
輸出
CLASS
瀨bjects:
- > JTabbedPane的OBJ()VAR:XXXXXXXXX:XXXXXXXX < -
:11:JTabbedPane中的jtpCount創建:--> in setCurrentJTabbedPane() var: <--
異常在線程 「主」 顯示java.lang.NullPointerException
在view.SetObjects.setCurrentJTabbedPane(SetObjects.java:385)
在view.SetObjects.obj(SetObjects.java:217)
在view.SchoolJDesktopPane.createInnerFrame(SchoolJDesktopPane.java:119)
在view.SchoolJDesktopPane。 (SchoolJDesktopPane.java:97 )
在view.Main.createJDesktopPane(Main.java:60)
在view.Main.main(Main.java:54)
你在** create **中初始化'currentJTabbedPane'的位置? – Ishtar 2010-10-29 01:39:44
我看到你已經更新了你的帖子,你現在傳遞'jtp'到setCurrentJTabbedPane。你剛解決了你的問題嗎? – 2010-10-29 01:44:47