title: Android: Getting string from cursor following a raw query in SQLITE
body: <p>I am trying to get a string back from a raw query to my SQLITE database.</p>
  
  <p>The issue is that I am bridging two tables, so I'm not sure how to call the column which contains the color (the value needed).</p>
  
  <p>How can I get the string value being returned from the SQL query to my result <code>variable</code>?</p>
  
  <pre><code>public String studentColor(){
      SQLiteDatabase db = getWritableDatabase();
  
      String queryStudent = "SELECT students.color FROM students, comments WHERE comments.author = students.name;";
      Cursor cursor = db.rawQuery(queryStudent, null);
      String result = // get students.color from cursor;
      return result
  }
  </code></pre>
  
  <p>Thanks</p>
  
  <p>EDIT</p>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.example.me.echoboard, PID: 21552
                    java.lang.IllegalStateException: Could not execute method for android:onClick
                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
                        at android.view.View.performClick(View.java:6213)
                        at android.widget.TextView.performClick(TextView.java:11074)
                        at android.view.View$PerformClick.run(View.java:23645)
                        at android.os.Handler.handleCallback(Handler.java:751)
                        at android.os.Handler.dispatchMessage(Handler.java:95)
                        at android.os.Looper.loop(Looper.java:154)
                        at android.app.ActivityThread.main(ActivityThread.java:6692)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
                     Caused by: java.lang.reflect.InvocationTargetException
                        at java.lang.reflect.Method.invoke(Native Method)
                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
                        at android.view.View.performClick(View.java:6213) 
                        at android.widget.TextView.performClick(TextView.java:11074) 
                        at android.view.View$PerformClick.run(View.java:23645) 
                        at android.os.Handler.handleCallback(Handler.java:751) 
                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                        at android.os.Looper.loop(Looper.java:154) 
                        at android.app.ActivityThread.main(ActivityThread.java:6692) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
                     Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
                        at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
                        at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
                        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
                        at com.example.me.echoboard.DBHandler.studentColor(DBHandler.java:121)
                        at com.example.me.echoboard.login.onClick(login.java:37)
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384) 
                        at android.view.View.performClick(View.java:6213) 
                        at android.widget.TextView.performClick(TextView.java:11074) 
                        at android.view.View$PerformClick.run(View.java:23645) 
                        at android.os.Handler.handleCallback(Handler.java:751) 
                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                        at android.os.Looper.loop(Looper.java:154) 
                        at android.app.ActivityThread.main(ActivityThread.java:6692) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
  </code></pre>