title: How to insert and fetch data from sqlite database in android?
body: <p>I have written this code to insert data in database through using "for" loop and I also want to see the data of database but the app is crashing.I can't find out its problem please help me...  </p>
  
  <pre><code>package com.smshah.database;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  
  
  public class MainActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      TextView t1=(TextView)findViewById(R.id.textView1);
      TextView t2=(TextView)findViewById(R.id.textView2);
      TextView t3=(TextView)findViewById(R.id.textView3);
  
      SQLiteDatabase db = openOrCreateDatabase("mapdb", MODE_PRIVATE, null);
      db.execSQL("CREATE TABLE IF NOT EXISTS maptb (rssi INT(4),xval INT(4),yval INT(4));");
      int x=0;
      int y=0;
      int r=0;
  
      for (int i = 0; i &lt;= 100; i++) 
      {
          db.execSQL("INSERT INTO maptb VALUES("+r+","+x+","+y+");");
          x = x + 1;
          r = r - 1;
      }
  
      Cursor resultSet = db.rawQuery("Select * from maptb",null);
      resultSet.moveToFirst();
      int rssi = resultSet.getInt(resultSet.getColumnIndex("rssi"));
      int xval = resultSet.getInt(resultSet.getColumnIndex("xval"));
      int yval = resultSet.getInt(resultSet.getColumnIndex("yval"));
  
      t1.setText(rssi);
      t2.setText(xval);
      t3.setText(yval);
  
      db.close();
  }
  
  }
  </code></pre>
  
  <p>logcat</p>
  
  <pre><code>08-04 03:12:17.842: W/ResourceType(13662): No package identifier when getting value for resource number 0x00000000
  08-04 03:12:17.852: D/AndroidRuntime(13662): Shutting down VM
  08-04 03:12:17.852: W/dalvikvm(13662): threadid=1: thread exiting with uncaught exception (group=0x40c0ea68)
  08-04 03:12:17.882: E/AndroidRuntime(13662): FATAL EXCEPTION: main
  08-04 03:12:17.882: E/AndroidRuntime(13662): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smshah.database/com.smshah.database.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.os.Handler.dispatchMessage(Handler.java:99)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.os.Looper.loop(Looper.java:137)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread.main(ActivityThread.java:4517)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at java.lang.reflect.Method.invoke(Method.java:511)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at dalvik.system.NativeStart.main(Native Method)
  08-04 03:12:17.882: E/AndroidRuntime(13662): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.content.res.Resources.getText(Resources.java:260)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.widget.TextView.setText(TextView.java:3680)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at com.smshah.database.MainActivity.onCreate(MainActivity.java:47)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.Activity.performCreate(Activity.java:4470)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
  08-04 03:12:17.882: E/AndroidRuntime(13662):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
  08-04 03:12:17.882: E/AndroidRuntime(13662):
  </code></pre>