title: inserting and view sqlite database error
body: <p>I have a broadcastreceiver to detect incoming sms and I'm storing the sms's in sqlite database. Then I'm trying to view the database content using query. The code was working perfectly when I wasn't using "id INTEGER PRIMARY KEY AUTOINCREMENT". After adding "id", when I try to view database content, its showing "No records found". So either its not entering values properly or there is error in view query code. I searched in other posts but not able find the error. Any help in this would be really helpful.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>Broadcastreceiver:
  
  public class MyBroadcast  extends BroadcastReceiver{
   
  Context mContext; 
  
  String msg_body;    
  String mob_no, name;
  String dttm, key;
  SQLiteDatabase db;
  
  
  @SuppressWarnings("deprecation")
  @Override
  public void onReceive(Context context, Intent intent) {
   // TODO Auto-generated method stub
   
   db=context.openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
   
       
    Bundle bundle = intent.getExtras();
       if (bundle != null) {
        Object[] pdus = (Object[])bundle.get("pdus");
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int i = 0; i &lt; pdus.length; i++) {
           messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
         }
            StringBuffer content = new StringBuffer();
             if (messages.length &gt; 0) {
               for (int i = 0; i &lt; messages.length; i++) {
                 content.append(messages[i].getMessageBody());
                 mob_no = messages[i].getOriginatingAddress();
                 Calendar calendar = Calendar.getInstance();
            Date finaldate = calendar.getTime();
            dttm = finaldate.toString();  
                 
               }
             }
             msg_body = content.toString();
             
             Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(mob_no));
             Cursor c = context.getContentResolver().query(lookupUri, new String[]{ContactsContract.Data.DISPLAY_NAME},null,null,null);
             try {
                 if(c.moveToFirst()){
                  name = c.getString(0);
                  
                  db.execSQL("INSERT INTO student (sender, timestamp, mesg) VALUES('"+name+"','"+dttm+"','"+msg_body+"');");
                 
               
                  
                 }else{
                  
                  
                  db.execSQL("INSERT INTO student (sender,timestamp,mesg) VALUES('"+mob_no+"','"+dttm+"','"+msg_body+"');");
                 }
                 
                 
             } catch (Exception e) {
                 // TODO: handle exception
             }finally{
                 c.close();
             }
        }
            
  
    
  
  }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>MainActivity:
  
  public class MainActivity extends Activity {
   
   SQLiteDatabase db;
    
  
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
       
    
    db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
    db.execSQL("CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, timestamp TEXT, mesg TEXT);");
    
   } //oncreate
   
   public void ViewAll(View v){
    try{
    Cursor c=db.rawQuery("SELECT * FROM student", null);
    if(c.getCount()==0)
    {
     showMessage("Error", "No records found");
     return;
    }
    StringBuffer buffer=new StringBuffer();
    while(c.moveToNext())
    {
     buffer.append("Sender: "+c.getString(1)+"\n");
     buffer.append("TimeStamp: "+c.getString(2)+"\n");
     buffer.append("Mesg: "+c.getString(3)+"\n\n");
    }
    showMessage("Student Details", buffer.toString());
    }
    catch(Exception ex)
    {
     System.out.println(ex.toString());
    }
   }
   
   
   public void Delete(View v){
    
    Cursor c=db.rawQuery("SELECT * FROM student WHERE id=(SELECT MIN(id) FROM student)", null);
    if(c.moveToFirst())
    {
     db.execSQL("DELETE FROM student WHERE id=(SELECT MIN(id) FROM student)");
     showMessage("Success", "Record Deleted");
    }
    else
    {
     showMessage("Error", "Invalid Entry");
    }
   }
  
   private void showMessage(String title, String message) {
    // TODO Auto-generated method stub
    Builder builder=new Builder(this);
       builder.setCancelable(true);
       builder.setTitle(title);
       builder.setMessage(message);
       builder.show();
   }
   
  
  
  } //activty</code></pre>
  </div>
  </div>
  </p>