title: What is causing the Exception in thread "pool-1-thread-2" (NullPointerException)
body: <p>I am creating a multi-threaded web server. When I run the client I receive a NullPointException. Why is this happening and what can be done to solve it?</p>
  
  <blockquote>
    <p>Concerning the suggestions that I should read the mentioned tutorial.  I have
    tried to solve the problem with the help of it. I created a
    constructor, but then I didn't know how to call the class: <code>
    theExecutor.execute(new Broadcaster (connection);</code></p>
    
    <p>I also created a setter:  <code>public void setQuestions(String[]
    questions) {
                this.questions[1] = questions[1];}</code></p>
    
    <p>That didn't help either. The String is initialized at the same place
    as <code>questions[0]</code>. I can print out <code>questions[1]</code> in the console. It
    get's its value from the ArrayList, but I do not know how to pass that
    value to the HandleValidation class. That seems to be the problem.
    If I have missed something in the tutorial that is an obvious solution, please tell me!</p>
  </blockquote>
  
  <p>Here you can read exception message and the stack trace:</p>
  
  <pre><code>Exception in thread "pool-1-thread-2" java.lang.NullPointerException
  at HandlleValidation.run(QuizServer.java:121)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745
  </code></pre>
  
  <p><strong>Here I am initializing the Executor which are handling the threads:</strong></p>
  
  <pre><code>public class QuizServer {
  public static void main(String[] args) throws IOException {
  
  ExecutorService theExecutor = Executors.newFixedThreadPool(10000);
      ServerSocket quizSocket = new ServerSocket(serverPort);
  
      try {
          while (true) {  //Skriver ut While True
              Socket connection = quizSocket.accept();
              theExecutor.execute(new Broadcaster(connection));
              theExecutor.execute(new HandlleValidation(connection));
          }
  </code></pre>
  
  <p><strong>The origin of the String questions[1] is in the Broadcaster class:</strong></p>
  
  <p>I am using a get and set method to make it possible for the other inner class to work with </p>
  
  <p><code>String questions[];</code></p>
  
  <pre><code>static class Broadcaster extends Thread {
  
      String quizFile = "src/qa.txt";
      private Socket connection;
  
      private PrintStream write;
      private String answer;
      private String questions[];
      int points = 0;
  
      public String[] getQuestions() {
          return questions;
      }
  </code></pre>
  
  <blockquote>
    <p>Here are the Strings <code>questions[0]</code> and <code>questions[1]</code>created:</p>
  </blockquote>
  
  <pre><code>while (true) {
  
                      for (String string : questionsList) {
                          String[] questions = string.split("/");
                          write.println(questions[0]);  //Printing out in client.
                          try {
                              Thread.sleep(4000); //"Sleeping" between the lines.
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
  </code></pre>
  
  <p><strong>The NullPointerException occurs in the HandleValidation class:</strong> </p>
  
  <blockquote>
    <p><code>class HandlleValidation extends Thread {</code></p>
  </blockquote>
  
  <p>The problem is caused by this line:</p>
  
  <pre><code>  if (answer.equals(questions[1])) {
                  points++;
                  writer.println("RÄTT SVAR! Du har " + points + " poäng");
  </code></pre>
  
  <p>The Setter:</p>
  
  <pre><code>public void setQuestions(String[] questions) {
      this.questions = questions;
  </code></pre>
  
  <blockquote>
    <p>I have tried to include as little of the code as possible to describe
    the problem. I may be able to give more information if requested!</p>
  </blockquote>