为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

繁花不似锦 2023-10-19 21:13:57
我尝试过仅使用字符串而不是数组中的数字,但它仍然不起作用。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");  }我希望这样,当他们选择“不”时,会显示一条消息,如果他们选择其他任何内容,我希望显示另一条消息。运行:在practice.pkg3.Practice3.main(Practice3.java:28) /Users/alexanderkiknadze/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53 线程“main”java.lang.NullPointerException 中出现异常: Java 返回: 1 BUILD FAILED (总时间: 12 秒)
查看完整描述

1 回答

?
慕婉清6462132

TA贡献1804条经验 获得超2个赞

您将 String[] 传递给 JOptionPane.showInputDialog。因此,根据选择,您将得到一个 String 而不是 String [] 。所以你应该改变你的代码

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])



查看完整回答
反对 回复 2023-10-19
  • 1 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信