我想要使用for循環從我的類文件中獲取名稱到String
數組,並將其顯示在JOptionPane
列表菜單中。但是,我面臨NullPointerException
,但如果我沒有將String
數組聲明爲null
,編譯器會抱怨。JOptionPane中的選項值
public void showWindow()
{
String[] theNames = null;
for(int i=0; i<person.length; i++)
{
if(person[i] != null)
{
System.out.println(person[i].name);
}
}
String s = (String)JOptionPane.showInputDialog(null, "Select your name and click on confirm", "Results", JOptionPane.PLAIN_MESSAGE, null, theNames, "Eric");
}
無需我一個一個地列出選項值,我該如何解決這個問題?
如何以及在哪裏填充'theNames'字符串數組? – Smit 2013-03-15 18:48:11