The following fragment of code is from a Java program that s

The following fragment of code is from a Java program that successfully compiles.

String name = JOptionPane.showInputDialog(null,
       \"Please enter your name\",
       \"Data Input\",
       JOptionPane.QUESTION_MESSAGE);

int count = name.length();

Briefly describe the potential problem that might arise when this code executes (assume that the program is not run in a headless environment).

Solution

Answer

JOptionPane.QUESTION_MESSAGE is used but the type of data expected is JOptionPane.INFORMATION_MESSAGE.

In this case JOptionPane.QUESTION_MESSAGE canl have a drop down list with nothing on the list and might expect some selection from the list but as the list is empty there is nothing to select, so there might be no alternative way to return.

The following fragment of code is from a Java program that successfully compiles. String name = JOptionPane.showInputDialog(null, \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site