I am requesting input from a user from a menu using the Scanner class in another class. For some unknown reason the program always hangs when the in.nextInt() line is included. I have manually commented out every line to determine that the problem is in the in.nextInt() line but have no idea why that would be an issue.
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
I have used a different scanner object to read text from a file earlier in my class but don't think that would be an issue. Any help would be greatly appreciated!
Edit: additional code
public void Manage() throws IOException, ListException
{
Scanner in = new Scanner(System.in);
//Console console = System.console();
System.out.println("1. Display items");
System.out.println("2. Add item");
System.out.println("3. Insert item");
System.out.println("4. Delete item");
System.out.println("5. Exit");
System.out.println("Enter option:");
int choice = in.nextInt();
//int choice = Integer.parseInt(System.console().readLine());
//choice = in.nextInt();
switch (choice)
{
//display
case 1:
System.out.println(dList);
break;
//add
case 2:
System.out.println("Please enter the address:");
String a = in.nextLine();
System.out.println("Please enter the square footage:");
double f = in.nextDouble();
System.out.println("Please enter the value:");
double v = in.nextDouble();
try
{
Dwelling x = new Dwelling(a,f,v);
dList.add(x);
}
catch (ListException e)
{
throw new ListException("damn");
}
break;
//insert
case 3:
System.out.println("Please enter the address:");
String ad = in.nextLine();
System.out.println("Please enter the square footage:");
double fo = in.nextDouble();
System.out.println("Please enter the value:");
double va = in.nextDouble();
int p = in.nextInt();
try
{
Dwelling y = new Dwelling(ad,fo,va);
dList.insert(y,p);
}
catch (ListException e)
{
throw new ListException("fuck");
}
System.out.println("Please enter the position to insert:");
break;
//delete
case 4:
System.out.println("Please enter the position to delete:");
int d = in.nextInt();
try
{
dList.delete(d);
}
catch (ListException e)
{
throw new ListException("omg");
}
break;
//exit
case 5:
break;
}
\\update data file
}//end of manage method
Edit: Here is a copy of my main method that I am using to test my class
public static void main(String [] args)
{
RealEstate2 r = new RealEstate2("SampleDwellings.txt");
r.Manage();
}//end of main