Home java The Local Variable InLines May Not Have Been Initialized

The Local Variable InLines May Not Have Been Initialized

Author

Date

Category

How to fix the error?

There is a code:

import java.io. *;
Public Class Startx {
/ **
 * @param args.
 * @Throws IoException
 * /
Public Static Void Main (String [] Args) Throws IoException {
  INT LINES;
  String [] InLines; // Exception in Thread "Main" java.lang.nullPointerexception
at startx.main (startx.java:17)
  BufferedReader Br = New InputStreamReader (System.in);
  Lines = (int) br.read ();
  For (int line = 1; Line & lt; = Lines; Line ++) {
    System.out.PrintLN (LINE + "]");
    InLines [Line] = Br.ReadLine ();
  }
  For (String Inline: InLines) System.out.printLN (Inline);
  }
}

which gives an error in the ad inline [] . And he gives it to it, being on the line:

inlines [line] = br.Readline (); // The Local Variable InLines May Not Have Been Initialized

As far as I understand, it is necessary to somehow a friend to declare InLines [] . But how?


Answer 1, Authority 100%

Try the following code:

import java.io. *;
Public Class Startx {
/ **
 * @param args.
 * @Throws IoException
 * /
Public Static Void Main (String [] Args) Throws IoException {
  INT LINES;
  String [] InLines; // Exception in Thread "Main" java.lang.nullPointerexception
at startx.main (startx.java:17)
  BufferedReader Br = New InputStreamReader (System.in);
  Lines = (int) br.read ();
  InLines = New String [Lines];
  For (int line = 1; Line & lt; = Lines; Line ++) {
    System.out.PrintLN (LINE + "]");
    InLines [Line] = Br.ReadLine ();
  }
  For (String Inline: InLines) System.out.printLN (Inline);
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions