title: table name = null; NullPointerException Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent
body: <p>I am having a problem with regards to checking records from the table and compare it to the word spoken. I am developing a text twist-like game.</p>
  
  <p>The variable <code>randomWord</code> is the result of the <code>random()</code> method.. The words from the database must be randomized before displaying to user and it shouldn't repeat in a session.</p>
  
  <p>BTW my problem is the <code>exists()</code> method; a <code>NullPointerException</code> occurs and it looks like it's because the table name is <code>null</code>. </p>
  
  <p>What should I do with this?</p>
  
  <p><strong><code>exists()</code> and <code>random()</code> method</strong></p>
  
  <pre><code> public boolean exists(String word) { 
           Cursor cursor = null;
  
           String WORD_TABLE = randomWord;
           System.out.println("exists: "+randomWord);
           String [] selectionArgs = {word + "%"};
  
           cursor = db.rawQuery("SELECT * from "+ WORD_TABLE + "WHERE Word like ?", selectionArgs);
  
          boolean exists = (cursor.getCount() &gt; 0);
  
          cursor.close();
  
          return exists;
      }
  
  
   public String random(){
  
  
       List&lt;Words&gt; words = getAllWords();      
  
  
      for (Words wrd : words) {
  
          String log = "WORDPOOL: "+ wrd.getWord() +" ID: "+ wrd.getId();
          stringList.add(wrd.getWord());
  
  
                // Writing Contacts to log
        Log.d("Name: ", log);
       } 
  
  
       selectedWord = randomGenerator.nextInt(stringList.size());
  
       System.out.println("HEY"+stringList.remove(selectedWord)+" "+selectedWord);
       randomWord = stringList.remove(selectedWord);
  
          return randomWord;
  
  }
  </code></pre>
  
  <p><strong><code>logcat</code></strong></p>
  
  <pre><code>07-20 16:49:04.171: E/AndroidRuntime(4081): FATAL EXCEPTION: main
  07-20 16:49:04.171: E/AndroidRuntime(4081): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.flip/com.flip.main.friend}: java.lang.NullPointerException
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.os.Looper.loop(Looper.java:130)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread.main(ActivityThread.java:3687)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at java.lang.reflect.Method.invoke(Method.java:507)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at dalvik.system.NativeStart.main(Native Method)
  07-20 16:49:04.171: E/AndroidRuntime(4081): Caused by: java.lang.NullPointerException
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at com.flip.dao.DBHelper.exists(DBHelper.java:107)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at com.flip.main.friend.onActivityResult(friend.java:289)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
  07-20 16:49:04.171: E/AndroidRuntime(4081):     ... 11 more
  </code></pre>
  
  <p><strong>The implementation</strong></p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      switch (requestCode) {
      case RESULT_SPEECH: {
          if (resultCode == RESULT_OK &amp;&amp; null != data) {
  
              ArrayList&lt;String&gt; text = data
                      .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
  
              txtText.setText(text.get(0));
              System.out.println(""+text.get(0));
              String wanted = text.get(0);
  
  
  
              if(dbHelp.exists(wanted)){
  
                  gameScore = text.get(0).length()*10;
  
                  TextView score = (TextView) findViewById(R.id.scoreView);
  
                  score.setText(""+gameScore);
  
  
                  playSound(R.raw.correct);
             }
      }
      }
  }
  </code></pre>