Reputation: 461
hi im trying to do a bit of small validation in my code but, when i try to try catch a large area of text (like the one below) i get the error message above the catch which says "Cannot Find Symbol" can someone point me in the right direction in what im doing wrong? Any help is appreciated
try{
while (option != 0) {
}//End Loop
} catch(InputMismatchException e) {
System.out.println("\nNot a number or an integer!\n");
option = menuSystem();
}
}
}//End OF Class
Upvotes: 4
Views: 17099
Reputation: 46428
its as if its looking for a class when i try and complie i get this error "symbol : class InputMismachException location: class Assigment.MenuResults }catch(InputMismachException e) 1 error"
Look at the error properly :
error "symbol : class InputMismachException location: class Assigment.MenuResults }catch(InputMismachException e) 1 error"
I assume you are running this code from notepad. if you are i recommend you use an IDE like Eclipse/netbean... now, coming to the error, it says it cant found InputMismachException. you are missing an import statement .
import it in your class like:
import java.util.InputMismatchException;
Upvotes: 0
Reputation: 22191
I guess your try/catch
is not included inside any method implementation.
The telltale is that you close curly brace of class just after catch
's curly brace! Where is the curly brace for method?
Do you have at least a main
method (or other) containing your code?
For sure, if you start coding just after the class declaration, this will lead to some alerts/errors. Example:
public class Job{
try{ //Unexpected token !!!
}
catch(Exception e){
}
}
Your issue is not caused by the missing identifier for exception. In that case, you would end up with a "identifer expected" alert.
Besides, remove the last curly brace after the end of class.
Upvotes: 4
Reputation: 26032
The java error cannot find symbol occurred when a Compiler does not recognize a class name. The following are the reason for such an error :
1)When a programmer misspelled the name of the class.
2When a programmer do not Imported the class name.
Read this document for more info and check your code again after reading this.
Upvotes: 1