how to solve the java.lang.NullPointerException? -


This is what I wrote for snakes and stairs. Please help me with the exceptions. The exception line is 72 and 114, I have highlighted the lines with comments that are heading towards the exception. Thanks in advance for the help.

  Package Practical 1; Import Java.io.Console; Import java.util.ArrayList; Import java.util.Scanner; Public square snakeandladder1 {int totalpos = 100; Int v = 0; Int [] score; Int score = 0; Int l = 0; Public Ink Foradis () {int i = 0; {While (i == 0) {i = (Math) Random () * 100; I = I% 13; } Came back; }} Public Anti Lender (Int Score) {if (Score == 15) Score = 30; And if (score == 45) score = 71; And if (score == 25) score = 62; And if (score == 81) score = 91; And if (score == 9) points = 39; Score [l] = score; Return score; } Public sank snat (int score) {if (score == 29) score = 11; And if (score == 81) score = 48; And if (score == 92) score = 71; And if (score == 30) score = 6; And if (score == 58) points = 19; Score [l] = score; Return score; } Zero Start () {System.out.println ("Enter the number of players:"); Scanner = new scanner (System.in); Int n = in.nextInt (); In.close (); L = n; System.out.println ("Enter Player Name in Order:"); ArrayList & LT; String & gt; Name 1 = New Arrestist & lt; String & gt; (); (For int i = 0; i & lt; n; i ++) {console = 1 in System.console (); String name 2 = in 1 Readline (); // ---- I'm getting this tap pointer exception here. Name1.add (NAME2); } While (true) {while (L> gt; {}} {System.out.println ("wx rolling die% d" + (L + 1)); Console in2 = System.console (); String Yes = in2.readLine (); If (yes == "Y") {v = throwdice (); } Score = score [L] + V; ((// ---) if all user input for scanner is replaced by empty indicator exception) (score == overall) {System.out.println ("user:" + name1.get (l) + " Found "+ v +" winner !!! "); break; } And if (score> placement) {score [l] = score [l]; } Int s1; S1 = ladder (score); If (S1 == score) {snake (score); } System.out.println ("present point" + 1 name .get (L) + "is:" + score [L]); L--; } If (L == 0) {l = n; }}} Public static zero master (string [] args) throws exceptions {// Todo auto-generated method stub snake and leader 1 cell = new sniper welder 1 (); ((// tap pointer exception even after the change here)) sal.start (); // ------ I'm getting this tap pointer exception here}   

}

  scanner = new scanner (System.in); Int n = in.nextInt (); In.close ();   

Please note that the close () method in the above code will not only close the object scanner but also the stream below it It will not be (i.e. keyboard input) from System.in and all other sources that implement readable .

When an < shutdown interface applies.

My suggestion: The scanner is closed, it will close its input source if the source Closeable Ul> < Li> in.close ();

  • Use name2 = in.readLine ();

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -