我嘗試過僅使用字符串而不是數(shù)組中的數(shù)字,但它仍然不起作用。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"); }我希望這樣,當(dāng)他們選擇“不”時(shí),會(huì)顯示一條消息,如果他們選擇其他任何內(nèi)容,我希望顯示另一條消息。運(yùn)行:在practice.pkg3.Practice3.main(Practice3.java:28) /Users/alexanderkiknadze/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53 線程“main”java.lang.NullPointerException 中出現(xiàn)異常: Java 返回: 1 BUILD FAILED (總時(shí)間: 12 秒)
1 回答

慕婉清6462132
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊
您將 String[] 傳遞給 JOptionPane.showInputDialog。因此,根據(jù)選擇,您將得到一個(gè) String 而不是 String [] 。所以你應(yīng)該改變你的代碼
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]);
以便它將用數(shù)組檢查對(duì)話框中的輸入seller.equals(seller[2])
。sellerInput.equals(seller[2])
添加回答
舉報(bào)
0/150
提交
取消