I am getting this error message when i run my program:
Could not open input1.txt
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Scanner.hasNext()" because "this.scanner" is null
at In.isEmpty(In.java:146)
at Board.readBoard(Board.java:22)
at Sudoku.main(Sudoku.java:75)
But i dont use scanner in the code what could possibly cause the error?
#What does this mean
45 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @gilded herald! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Here are the lines that is says the problem is at:
boolean boardIsMade = Board.readBoard(tableau,N,ifile); (line:75)
while(!ifile.isEmpty() && i < N && j < N ) { (line:22)
the other line it says its with scanner but i dont use scanner anywhere in the code idk why is says that
What about In.java:146?
return !scanner.hasNext();
} ```
This message has been formatted automatically. You can disable this using /preferences.
in class in included in StdIn i think i might be wrong
i only use the StdIn library tho nothing else
What is StdIn library?
// do this once when StdIn is initialized
static {
resync();
}
/**
* If StdIn changes, use this to reinitialize the scanner.
*/
private static void resync() {
setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME));
}
private static void setScanner(Scanner scanner) {
StdIn.scanner = scanner;
StdIn.scanner.useLocale(LOCALE);
}
Ouch
wdym ouch?
That's a terrible thing.
But also I don't know why it doesn't work. Did you modify this code in any way?
nah
i just imported it as it is to my program
do you think there is a chance the problem is in my settings?
like they are not setup properly to read from files?
Unlikely. It's a very simple mechanism. The static section should be executed as soon as the class imported for the first time.
Can you confirm that lines I posted above are still in In.java file?
yeah 1 sec
it doesnt seem to be there
i tried ctrl + f and then pasted the lined but i found nothing
should i paste them in the file?
Yeah, but I would also try to find out why they isn't there.
Nvm i cant paste them, it doesnt let me write anything in the In.java file
https://introcs.cs.princeton.edu/java/84network/In.java.html
this is the In.java file
the lines that you found should be in the StdIn file
Wait, what?
the In.java file is the one that i just sent
StdIn is a library containing this file
i think i am not sure tho
How do you use that StdLib thing that you can't edit the file?
i just import it to my programs so i can extra stuff
Is it in a jar file?
Seriously I would just drop that StdIn. I don't trust libraries maintained by academics.