title: Android Variable not passing to DB helper class
body: <p>I have an app that needs to access a static database and run queries based on user input.  I am using </p>
  
  <p>jgilfelt/android-sqlite-asset-helper</p>
  
  <p>as my Database helper class.  My main activity has 2 spinners that the user can use to narrow down a search.  The spinners return the a string variable named mGenre and mDecade respectively.  at the bottom of the activity is a button to proceed.  When the button is pushed an intent fires to bring up a new activity that displays a song title at random.  The variables are passed to the new activity vi the intent with the putExtra().  The new activity recieves the variable and uses them in if/else if statements to decide which query to run from the DB Helper.  </p>
  
  <p>In the DB helper class, I create an instance of the new class and us it to set the mGenre and mDecade variables so that the proper query is running, using the variables inside of the String[] args section of rawQuery().</p>
  
  <p>Here is the songActivity class that is opened when the user hits the button on the Main Activity:</p>
  
  <pre><code>public class SongActivity extends ActionBarActivity {
  
      private MyDatabase db;
      private static  final String TAG = "We got ";
  
      String mGenre;
      String mDecade;
  
  
      public String getGenre() {
          return mGenre;
      }
  
      public String getDecade() {
          return mDecade;
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_song);
  
          //when activity launches query database using user params
  
          mGenre = getIntent().getExtras().getString("Genre");
          mDecade = getIntent().getExtras().getString("Decade");
          Log.v(TAG, mGenre);
          Log.v(TAG, mDecade);
  
          String songTitle = "";
          String songArtist = "";
          String songYear = "";
  
          TextView mSongTitle = (TextView)findViewById(R.id.songTitle);
          TextView mSongArtist = (TextView)findViewById(R.id.songArtist);
          TextView mSongYear = (TextView)findViewById(R.id.songYear);
  
  
  
  
          db= new MyDatabase(this);
  
  
  
  
          if (mGenre.equals("*") &amp;&amp; mDecade.equals("*")) {
  
              Cursor cursor = db.kamikazeSelected();
              cursor.moveToFirst();
              while (!cursor.isAfterLast()) {
                  songTitle = cursor.getString(1);
                  songArtist = cursor.getString(2);
                  songYear = cursor.getString(4);
                  Log.i(TAG, String.valueOf(songTitle));
                  cursor.moveToNext();
              }
              cursor.close();
              db.close();
  
          }
          else if (!mGenre.equals("*") &amp;&amp; mDecade.equals("*")) {
              Cursor cursor = db.genreSelected();
  
              cursor.moveToFirst();
              while (!cursor.isAfterLast()) {
                  songTitle = cursor.getString(1);
                  songArtist = cursor.getString(2);
                  songYear = cursor.getString(4);
  //                Log.i("cursor", cursor.getString(1));
                  Log.i(TAG, String.valueOf(songTitle));
                  cursor.moveToNext();
              }
              cursor.close();
              db.close();
          }
  
          else if (mGenre.equals("*") &amp;&amp; !mDecade.equals("*")) {
              Cursor cursor = db.decadeSelected();
              cursor.moveToFirst();
              while (!cursor.isAfterLast()) {
                  songTitle = cursor.getString(1);
                  songArtist = cursor.getString(2);
                  songYear = cursor.getString(4);
                  Log.i(TAG, String.valueOf(songTitle));
                  cursor.moveToNext();
              }
              cursor.close();
              db.close();
          }
  
          else if (!mGenre.equals("*") &amp;&amp; !mDecade.equals("*")) {
              Cursor cursor = db.bothSelected();
              cursor.moveToFirst();
              while (!cursor.isAfterLast()) {
                  songTitle = cursor.getString(1);
                  songArtist = cursor.getString(2);
                  songYear = cursor.getString(4);
                  Log.i(TAG, String.valueOf(songTitle));
                  cursor.moveToNext();
              }
              cursor.close();
              db.close();
          }
          mSongTitle.setText(songTitle);
          mSongArtist.setText(songArtist);
          mSongYear.setText(songYear);
  
  
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
  
  }
  </code></pre>
  
  <p>and here is the database helper class:</p>
  
  <pre><code>public class MyDatabase extends SQLiteAssetHelper {
  
      private static  final String TAG = "Variable for query is ";
      private static final String DATABASE_NAME = "mankiniDB.sqlite";
      private static final int DATABASE_VERSION = 1;
  
  
  
  
  
  
      public MyDatabase(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
  
      SongActivity mSongActivity = new SongActivity();
      String mGenre = mSongActivity.getGenre();
      String mDecade = mSongActivity.getDecade();
  
  
  
  
  
      public Cursor kamikazeSelected() {
          SQLiteDatabase db = getReadableDatabase();
  
          Cursor cursor =db.rawQuery("SELECT * FROM songList ORDER BY random() limit 1", null);
  
          return cursor;
      }
  
      public Cursor genreSelected() {
          SQLiteDatabase db = getReadableDatabase();
  
          Cursor cursor =db.rawQuery("SELECT * FROM songList WHERE Genre = ? ORDER BY random() limit 1", new String[] {mGenre});
  
          return cursor;
      }
  
      public Cursor decadeSelected() {
          SQLiteDatabase db = getReadableDatabase();
  
          Cursor cursor =db.rawQuery("SELECT * FROM songList WHERE Decade = ? ORDER BY random() limit 1", new String[] {mDecade});
          return cursor;
      }
  
      public Cursor bothSelected() {
  
          SQLiteDatabase db = getReadableDatabase();
  
          Cursor cursor =db.rawQuery("SELECT * FROM songList WHERE Decade = ? AND Genre = ? ORDER BY random() limit 1", new String[] {mDecade, mGenre});
  
          return cursor;
      }
  
  }
  </code></pre>
  
  <p>Here is the LogCat error stack trace:</p>
  
  <pre><code>03-19 21:35:54.256    1751-1751/tomschinler.thegreatman_kiniskamikazekaraoke I/SQLiteAssetHelper﹕ successfully opened database mankiniDB.sqlite
  03-19 21:35:54.260    1751-1751/tomschinler.thegreatman_kiniskamikazekaraoke D/AndroidRuntime﹕ Shutting down VM
  03-19 21:35:54.264    1751-1751/tomschinler.thegreatman_kiniskamikazekaraoke W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4b61648)
  03-19 21:35:54.276    1751-1751/tomschinler.thegreatman_kiniskamikazekaraoke E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{tomschinler.thegreatman_kiniskamikazekaraoke/tomschinler.thegreatman_kiniskamikazekaraoke.SongActivity}: java.lang.IllegalArgumentException: the bind value at index 1 is null
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5103)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
              at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
              at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
              at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
              at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
              at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
              at tomschinler.thegreatman_kiniskamikazekaraoke.MyDatabase.genreSelected(MyDatabase.java:50)
              at tomschinler.thegreatman_kiniskamikazekaraoke.SongActivity.onCreate(SongActivity.java:82)
              at android.app.Activity.performCreate(Activity.java:5133)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5103)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The problem is that no matter what I do, or where I set the variables, The database helper class recives and empty variable that results in a null argument.  I need the user's input complete the query.  But it is always null.  Please help me see what I am missing.</p>