Skip to main content

Help with JOptionPane.showInputDialog

1 reply [Last post]
Joined: 2006-02-17

I am trying to create an input pane with multiple input messages, but having problem declaring result object.

private static int calcPay()
double rate, grossPay, taxRate, credit, netPay, finalPay;
int hours, check = 0;
String state;

JFrame inputFrame = new JFrame();
Object[] answers;
Object[] questions = {"Hours worked:",
"Pay Rate:",
"Home State"};
answers = JOptionPane.showInputDialog(questions);


C:\MyJava\ incompatible types
found : java.lang.String
required: java.lang.Object[]
answers = JOptionPane.showInputDialog(questions);
1 error

Tool completed with exit code 1

From API:
A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type:

An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet


I'm not able to reproduce this.
What JDK are you using?