title: Get data from database using cursor
body: <p>I'm trying to take data from my database. I did getter in Java class and I send it to another Java class. This is how it looks: </p>
  
  <h2><code>DatabaseHelper</code></h2>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper {
  
      private static final String TAG = "DatabaseHelper";
  
      private static final String TABLE_NAME = "pushup_table";
      private static final String COL1 = "ID";
      private static final String COL2 = "number";
  
  
      public DatabaseHelper(Context context) {
          super(context, TABLE_NAME, null, 1);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
                  COL2 +" TEXT)";
          db.execSQL(createTable);
      }
  public String getNumber(int i){
      SQLiteDatabase db = this.getWritableDatabase();
      String query = "SELECT " + COL2 + " FROM " + TABLE_NAME +
              " WHERE " + COL1 + " = '" + i + "'";
      Cursor data = db.rawQuery(query, null);
      //String cursorString = data.getString( data.getColumnIndex(COL1));
      String cursorString = data.getString(0);
      return cursorString;
  }}
  </code></pre>
  
  <h2><code>test</code></h2>
  
  <pre><code>public class test extends AppCompatActivity {
  DatabaseHelper mDatabaseHelper;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.test);
          ButterKnife.bind(this);
  
          mDatabaseHelper = new DatabaseHelper(this);
  
      }
   @OnClick(R.id.button_data)
      public void data(){
  
          String numberFromDB = mDatabaseHelper.getNumber(1);
  
          Toast.makeText(this,"number from db: " + numberFromDB, Toast.LENGTH_SHORT).show();
  
      }
  }
  </code></pre>
  
  <p>But it gives me these errors and nothing happened (when I have my phone connected)</p>
  
  <pre><code>E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
  E/Minikin: Could not get cmap table size!
  E/vndksupport: Could not load vendor/lib64/egl/libGLES_mali_v2.so from sphal namespace: dlopen failed: library "vendor/lib64/egl/libGLES_mali_v2.so" not found.
  </code></pre>
  
  <p>I also have some data in the database of course. </p>
  
  <p>When I tried this on emulator shows different errors:</p>
  
  <pre><code>07-14 19:20:56.702 9681-9681/majer.pompeczki E/AndroidRuntime: FATAL EXCEPTION: main
      Process: majer.pompeczki, PID: 9681
      android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
          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 majer.pompeczki.DatabaseHelper.getNumber(DatabaseHelper.java:81)
          at majer.pompeczki.test.trening(test.java:68)
          at majer.pompeczki.test_ViewBinding$3.doClick(test_ViewBinding.java:62)
          at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
          at android.view.View.performClick(View.java:5610)
          at android.view.View$PerformClick.run(View.java:22265)
          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:6077)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
  </code></pre>