one error in Java code Please help?

Hi everyone

I am writing this code that uses an input box that has three choices and I am having trouble parsing the value afterward :

import java.io.*;
import javax.swing.JOptionPane;

public class MyType
{
public static void main (String[] args)
{
// Declare and Construct Variables
String strChoice, strTryString, strTryInt, strTryDouble;
int choice, tryInt;
double tryDouble;
boolean done = false;

//loop while user does not click cancel button
while(!done)
{

try
{
String message = "What is My Type?" +
"\n\n1) String\n2) Integer\n3) double\n4) Quit the program\n\n";
choice = Integer.parseInt(strChoice);

switch(choice)
{
case 1:
JOptionPane.showMessageDialog(null, "Correct, any input can be saved as a String");
break;

case 2:
JOptionPane.showMessageDialog(null, "Correct");
tryInt = Integer.parseInt(strChoice);
break;

case 3:
JOptionPane.showMessageDialog(null, "Correct");
tryDouble = Integer.parseInt(strChoice);
break;

case 4:
JOptionPane.showMessageDialog(null, "Exit.");
done = true;
break;

default:
throw new NumberFormatException();
}
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Please try again");
}
}
}
}

Thank You :-)

2012-02-02T12:05:21Z

This is the error: C:\Users\user\Desktop\MyType.java:31: variable strChoice might not have been initialized
choice = Integer.parseInt(strChoice);
^
1 error

Thank You :-)

coolguy15012012-02-02T12:25:20Z

Favorite Answer

You haven't assigned the user input value to strChoice.