the codes running ok on NetBeans, and wih the error messages while I am running the jar file. Any helps with the following code would be very appreciated.

Scanner file = null;

while(file.hasNext()){
          if (file.hasNextInt()) list.add(file.nextInt());
              else file.next();
      }

Recommended Answers

All 2 Replies

how can file have a next? you haven't even initialized file, you just declared it to be null.
so, with: file.hasNext()
you are calling a method on null. that is what causes the NullPointerException.

if this is not your issue, please provide the correct code and stacktrace.

Replace your code as :

Scanner scan = new Scanner(System.in); // Or whichever stream your //program is trying to read from ... I would have used InputStreams //instead

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.