如何将 JOptionPane.showInputDialog 与数组一起使用?



我已经尝试只使用字符串而不是数组中的数字,但它仍然不起作用。

String [] seller  = { "Yeah", "Nah" ,"Depends on what it is"};
seller = (String[]) JOptionPane.showInputDialog(null, "Hey, you want to see something cool","Scam3r69 has entered chat", 1, null, seller, seller[1]); 
if (seller.equals(seller[2])){
JOptionPane.showMessageDialog(null, "Just let me say what it is okay");
}
else{
JOptionPane.showMessageDialog(null,"It's a chance to make 1 million dollars in 1 minute");  
}

我希望当他们选择"否"时会显示一条消息,如果他们选择其他任何内容,我希望显示不同的消息。

run: 线程 "main" java.lang.NullPointerException at 中的异常 practice.pkg3.Practice3.main(Practice3.java:28(/Users/alexanderkiknadze/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: 返回的 Java:1 次构建失败(总时间:12 秒(

你正在将String[]传递给你的JOptionPane.showInputDialog。因此,根据选择,您将获得一个字符串而不是字符串 [] 。Sof 你应该改变你的代码

seller = (String[]) JOptionPane.showInputDialog(null, "Hey, you want to see something cool","Scam3r69 has entered chat", 1, null, seller, seller[1]); 


String sellerInput = (String) JOptionPane.showInputDialog(null, "Hey, you want to see something cool","Scam3r69 has entered chat", 1, null, seller, seller[1]); 

seller.equals(seller[2])sellerInput.equals(seller[2]),以便它将检查带有数组的对话框中的输入。

最新更新