title: SQLite - delete by id not deleting table row
body: <p>In my databse I have simple table named <code>Place(id,place_name,latitude,longitude,place_details)</code></p>
  
  <p>I want to delete a row on ListView's item click.</p>
  
  <p>I have tried following:</p>
  
  <p><strong>Place.java</strong></p>
  
  <pre><code>public class Place {
      int _id;
      private String _name;
      private double _latitude,_longitude;
      private String _placedetails;
  
  
      public Place(int id, String name, double latitude, double longitude,String placedetails)
          {
              this._id = id;
            this._name = name;
            this._latitude = latitude;
              this._longitude = longitude;
              this._placedetails = placedetails;
  
  
      }
  
      public Place(String name, double latitude, double longitude,String placedetails)
      {
  
          this._name = name;
          this._latitude = latitude;
          this._longitude = longitude;
          this._placedetails = placedetails;
  
      }
  
      public Place() {
  
      }
      public int getID(){
          return this._id;
      }
  
  
      public void setID(int id){
          this._id = id;
      }
  
      public void setname(String placename)
      {
          this._name = placename;
  
  
      }
  
      public String getname()
      {
          return this._name;
  
  
      }
  
      public void setlatitude(double latitude)
      {
          this._latitude=latitude;
  
  
      }
  
      public double getlatitude()
      {
          return this._latitude;
  
  
      }
  
  
      public void setlongitude(double longitude)
      {
          this._longitude = longitude;
  
  
      }
  
      public double getlongitude()
      {
          return this._longitude;
  
  
      }
  
  
      public void  setPlacedetails(String placedetails)
      {
  
          this._placedetails = placedetails;
      }
  
  
      public String getplacedetails()
      {
          return this._placedetails;
      }
  
  
  }
  </code></pre>
  
  <p>The Activity in which I want to insert places has something like:</p>
  
  <pre><code>  MySqliteHelper db = new MySqliteHelper(this);
  
    db.addPlaces(new Place(myplacename, mylatitude, mylongitude, myplacedetails));
  </code></pre>
  
  <p>As explained here: <a href="https://stackoverflow.com/questions/7594541/android-table-creation-failure-near-autoincrement-syntax-error">Android table creation Failure (near &quot;autoincrement&quot;: syntax error)?</a>  , I don't think I need to explicitly id. It will be created for each object of Place. //Am I wrong here?</p>
  
  <p>In ListView's onitemclicklistener, following code is for deleting place:</p>
  
  <pre><code>  Place place = places_adapter.getItem(pos);
    db.deletePlaces(place);
  </code></pre>
  
  <p>And In <strong>MySQLiteHelper</strong> which extends <code>SQLiteHelper</code>, methods are as following:</p>
  
  <pre><code>public void addPlaces(Place place)
      {
  
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues convalues = new ContentValues();
  
  
          convalues.put(KEY_PLACENAME,place.getID());
          convalues.put(KEY_PLACENAME,place.getname());
          convalues.put(KEY_LATITUDE,place.getlatitude());
          convalues.put(KEY_LONGITUDE,place.getlongitude());
          convalues.put(KEY_PLACEDETAILS,place.getplacedetails());
  
            db.insert(TABLE_NAME, null, convalues);
            Log.d("my","db.insert(TABLE_NAME, null, convalues)");
            Log.d("my", "Values inserted");
            db.close();
  
      }
  
      public void deletePlaces(Place place)
      {
          SQLiteDatabase db = this.getWritableDatabase();
  
          int id = place.getID();
  
          Log.d("my",Integer.toString(id));
          db.delete(TABLE_NAME, KEY_ID + " = ?",
                  new String[]{Integer.toString(id)} );
          db.close();
      }
  </code></pre>
  
  <p>While deleting, in logcat the value of <code>id</code> is showing always <code>0</code>....and according table row is not deleteing from database.</p>
  
  <p>Please help me if anyone know anything is wrong.</p>