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
With that much parameters, the method showInputDialog
doesn't return a String but an Object as stated in the javadoc
As suggested in the Swing tutorial , you simply have to cast the result to String.
String val = (String) JOptionPane.showInputDialog(null,
"Search item to Edit ",
"Warning",
JOptionPane.QUESTION_MESSAGE,
null,
new String[]{"Item name", "Item no.","Price"},
"");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.