title: Android How To Get The Return Value String From SQLite Cursor Query And Display It In Edittext?
body: <p>When I run the SQLite Cursor Query it fails to display the result string in the edittext.</p>
  
  <p>It fails with the Logcat message:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity
  android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
  </code></pre>
  
  <p>How can I get the query result value string from the cursor and display it in the edittext?</p>
  
  <pre><code>public class Books extends Activity implements OnClickListener {
  
   private BooksData books;
  
   @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.books);
  
          books = new BooksData(this);
  
          }
  
          SQLiteDatabase db1 = books.getReadableDatabase();
  
          SEARCH_TERM = "math";
  
          EditText edittext = (EditText) findViewById(R.id.edittext1);
  
          // Get the value from TITLE when the TOPIC value is specified, ie such as "math".
  
          Cursor cursor_2 = db1.query(TABLE_NAME, new String[] {"_id", "TOPIC", "TITLE"}, "TOPIC = ?", new String[]{ ""+SEARCH_TERM+"" }, null, null, null, null);
  
          String TEMP_DATA = cursor_2.getString(2);
  
          edittext.setText(TEMP_DATA);
  
  books.close();
  cursor_2.close();
  }
  </code></pre>