[英]As far as I know showinputdialog returns an output of type string but it gives me an error that it cannot convert the object to a String
String val = JOptionPane.showInputDialog(null,
"Search item to Edit ",
"Warning",
JOptionPane.QUESTION_MESSAGE,
null,
new String[]{"Item name", "Item no.","Price"},
"");
Error:错误:
incompatible types: Object cannot be converted to String
不兼容的类型:Object 无法转换为字符串
With that much parameters, the method showInputDialog
doesn't return a String but an Object as stated in the javadoc有了这么多参数,
showInputDialog
方法不返回字符串,而是返回 Object,如javadoc中所述
As suggested in the Swing tutorial , you simply have to cast the result to String.正如Swing 教程中所建议的,您只需将结果转换为字符串。
String val = (String) JOptionPane.showInputDialog(null,
"Search item to Edit ",
"Warning",
JOptionPane.QUESTION_MESSAGE,
null,
new String[]{"Item name", "Item no.","Price"},
"");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.