I’m trying to create an input dialog, using a static method of JOptionPane:
public static Object showInputDialog(Component parentComponent,
Object message,
String title,
int messageType,
Icon icon,
Object[] selectionValues,
Object initialSelectionValue)
throws HeadlessException
My code is as follows:
String username = JOptionPane.showInputDialog(null,
"Username",
"Pick a name",
JOptionPane.PLAIN_MESSAGE,
null,
null,
"default_name");
This gets me the error:
ChatController.java:49: incompatible types
found : java.lang.Object
required: java.lang.String
There must be something simple I’m missing…
JOptionPane.showInputDialog()returns an object, as specified in the doc, but you’re expecting a String. Note that the selection optionsis an array of
Objects, so you’ll get one of those objects back. There’s nothing to say they’re specified as strings. If the values are strings, then you can/should cast appropriately.Note also you’re passing a null array. From the doc: