我想要使用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