I have to use Scanner objects in different scopes as presented below:
public String fidentifier (String u)
{
try {
Scanner t = new Scanner( new File( "ubasic.dat") );
//Some Statements
} catch( FileNotFoundException e ){
System.out.println( "Exception : " + e );
}
}
public String didentifier(String cat)
{
try {
if( cat.equals("Government") )
Scanner s = new Scanner( new File("ugov.dat") );
else
Scanner s = new Scanner( new File("uhc.dat") );
//Some Statements
} catch( FileNotFoundException e ) {
System.out.println( "Exception : " + e );
}
}
As I clearly declared Scanner objects in two different methods, I am still getting error pointing out that Scanner object declaration is not allowed in method didentifier()
.
Point me out where I'm wrong.