#What does this mean

45 messages · Page 1 of 1 (latest)

gilded herald
#

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?

worthy caveBOT
#

This post has been reserved for your question.

Hey @gilded herald! Please use /close or the Close Post button 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.

gilded herald
#

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

lusty tendon
#

What about In.java:146?

cedar pathBOT
#
        return !scanner.hasNext();
    } ```

This message has been formatted automatically. You can disable this using /preferences.

gilded herald
#

in class in included in StdIn i think i might be wrong

#

i only use the StdIn library tho nothing else

lusty tendon
#

What is StdIn library?

lusty tendon
#

    // 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

gilded herald
#

wdym ouch?

lusty tendon
#

That's a terrible thing.

#

But also I don't know why it doesn't work. Did you modify this code in any way?

gilded herald
#

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?

lusty tendon
#

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?

gilded herald
#

yeah 1 sec

#

it doesnt seem to be there

#

i tried ctrl + f and then pasted the lined but i found nothing

gilded herald
lusty tendon
#

Yeah, but I would also try to find out why they isn't there.

gilded herald
#

Nvm i cant paste them, it doesnt let me write anything in the In.java file

#

the lines that you found should be in the StdIn file

lusty tendon
#

Wait, what?

gilded herald
#

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

lusty tendon
#

How do you use that StdLib thing that you can't edit the file?

gilded herald
#

i just import it to my programs so i can extra stuff

lusty tendon
#

Is it in a jar file?

#

Seriously I would just drop that StdIn. I don't trust libraries maintained by academics.

gilded herald
#

I have to use it

#

Its in the excersice ibstructions

lusty tendon
#

Can you post the code that you have in your In.java file?

#

The one that you have locally.

gilded herald
#

I closed my pc sorry

#

Ty for helping me

#

I will send it to you tomm if you have some time