我正在尝试从多维表中的项目填充 JCombobox。我试图宣传的项目是该表中城市的名称。这是我的代码:
String t21[][] = {{"Azores","Alaska","Pacific Time US & Canada","Chihuahua, La Paz, Mazatlan - New","Guadalajara, Mexico City, Monterrey - New","Bogota, Lima, Quito, Rio Branco","Atlantic Time","CasaBlanca GMT","Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna","Athens, Bucharest, Istanbul","Moscow, St. Petersburg, Volgograd","Abu Dhabi, Muscat","Chennai, Kolkata, Mumbai, New Delh","Almaty, Novosibirsk","Bangkok, Hanoi, Jakarta","Beijing, Chongqing, Hong Kong, Urumqi","Osaka, Sapporo, Tokyo","Canberra, Melbourne, Sydney","",""},
{"-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7","8","9","10"}};
for( int i = 0; i< t21.length-1; i++){
jComboBox1.addItem(t21[0][i]);
}
但是当我运行我的程序时,我得到了这个错误:
java.awt 的 java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) 的 temps.interfac$2.run(interfac.java:125) 的线程“AWT-EventQueue-0”java.lang.NullPointerException 中的异常.EventQueue.dispatchEventImpl(EventQueue.java:727) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:688) at java.awt.EventQueue$3 .run(EventQueue.java:686) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java: 697) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) 在 java.awt 的 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)。EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread .java:91)