title: How to check if thread finished execution Android Studio
body: <p>I am trying to create an app that contains 2 spinners with data from a data base. When a button is pressed, a new intent is created, showing the 2 spinners. The problem is that I have to create the DB queries in a new thread, and when I run the app, I get a null pointer exception (as far as my understanding goes, it is because the array in which I store the DB data is not yet populated). 
  My question is, how can I delay the creation of the spinners until the queries from the DB are made?
  Below is a sample code of my implementation:
  The intent where I create the spinners and make a call to a class that makes the DB queries:</p>
  
  <pre><code>String [][] dbData; //the array where i store data from DB
  getDBdata myData = new getDBdata(); // create a new instance of the class that queries the DB
  dbData = myData.getData(); // I get the data
  Log.e("My log: ", String.valueOf(dbData.length)); //and here it crashes, giving me a null pointer exception
  </code></pre>
  
  <p>And the class where I create a new thread to make a DB query:</p>
  
  <pre><code>public getDBdata()
  {
      Thread thread = new Thread(new Runnable(){
          @Override
          public void run() {
              DBconn(); //make a DB query 
          }
      });
      thread.start();
  }
  public String[][] getData()
  {
      return data;
  }
  </code></pre>