delete a row in android sqlite table
<p>i want to delete a row in the database table
i using a listview and after longclick the listitem you will get alert dialog to show edit and delete method
when i click the edit method the emulator goes fine, but when i click the delete method, there comes the force close notification,.im new to android programming,
can you explain what is the problem with my code
this is my code
for database helper:</p>

<pre><code>import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

class PuraHelper extends SQLiteOpenHelper {

private SQLiteDatabase db;
public final String TABLE_NAME = "pura";
public final String TABLE_ROW_ID = "_id";
public final String NAMA_PURA = "nama_pura";
public final String KABUPATEN = "kabupaten";
public final String JALAN = "jalan";
public final String LONGITUDE = "longitude";
public final String LATITUDE = "latitude";
public final String KETERANGAN = "keterangan";

private static final String DATABASE_NAME="PPB.db";
private static final int SCHEMA_VERSION=1;

public PuraHelper(Context context) {
    super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String CreateTablePura="create table"+TABLE_ROW_ID+"INTEGER PRIMARY KEY AUTOINCREMENT,"+ NAMA_PURA + "TEXT," + KABUPATEN + "TEXT,"+ JALAN + "TEXT," +LONGITUDE + "TEXT," + LATITUDE + "TEXT," + KETERANGAN + "TEXT";
    db.execSQL(CreateTablePura);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // no-op, since will not be called until 2nd schema
    // version exists
}

public Cursor getAll() {
    String SelectAll = "SELECT _id, nama_pura, kabupaten, jalan, longitude, latitude, keterangan FROM pura ORDER BY nama_pura";
    return(getReadableDatabase()
                    .rawQuery(SelectAll,
                            null));
}

public Cursor getById(String id) {
    String SelectById = "SELECT _id, nama_pura, kabupaten, jalan, longitude, latitude, keterangan FROM pura WHERE _ID=?";
    String[] args={id};
    return(getReadableDatabase()
                    .rawQuery(SelectById, args));
}

public void insert(String nama_pura, String kabupaten, String jalan, String longitude, String latitude, String keterangan) {
    ContentValues cv=new ContentValues();

    cv.put("nama_pura", nama_pura);
    cv.put("kabupaten", kabupaten);
    cv.put("jalan", jalan);
    cv.put("longitude", longitude);
    cv.put("latitude", latitude);
    cv.put("keterangan", keterangan);
    getWritableDatabase().insert("pura", "nama", cv);
}

public void update(String id, String nama_pura, String kabupaten, String jalan, String longitude, String latitude, String keterangan) {
    ContentValues cv=new ContentValues();
    String[] args={id};

    cv.put("nama_pura", nama_pura);
    cv.put("kabupaten", kabupaten);
    cv.put("jalan", jalan);
    cv.put("longitude", longitude);
    cv.put("latitude", latitude);
    cv.put("keterangan", keterangan);
    getWritableDatabase().update("pura", cv, "_ID=?", args);
}

public void deleteRow(long rowId)
{
    // ask the database manager to delete the row of given id
    //db.delete(TABLE_NAME, TABLE_ROW_ID + "=" + rowId, null);

    db.delete(TABLE_NAME, TABLE_ROW_ID + "="+rowId,null);

}


public String getId(Cursor c) {
    return(c.getString(0));
}
public String getNama(Cursor c) {
    return(c.getString(1));
}
public String getKab(Cursor c) {
    return(c.getString(2));
}
public String getJalan(Cursor c) {
    return(c.getString(3));
}
public String getLong(Cursor c) {
    return(c.getString(4));
}
public String getLat(Cursor c) {
    return(c.getString(5));
}
public String getKet(Cursor c) {
    return(c.getString(6));
}
</code></pre>

<p>for my java class:</p>

<pre><code>import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemLongClickListener;

public class db_list extends ListActivity {

protected static final String ID_EXTRA = "com.jigler.ppb._ID";
PuraHelper helper=null;
Cursor model=null;
PuraAdapter adapter=null;

EditText    etNama, etKabupaten,etJalan, etLong, etLat, etKeterangan;
Button      bSave, bCancel;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_list);

    helper=new PuraHelper(this);

    etNama = (EditText)findViewById(R.id.etNama);
    etKabupaten = (EditText)findViewById(R.id.etKabupaten);
    etJalan = (EditText)findViewById(R.id.etJalan);
    etLong = (EditText)findViewById(R.id.etLong);
    etLat = (EditText)findViewById(R.id.etLat);
    etKeterangan = (EditText)findViewById(R.id.etKeterangan);

    model=helper.getAll();
    startManagingCursor(model);
    adapter=new PuraAdapter(model);
    setListAdapter(adapter);

     ListView lv = getListView();
     lv.setLongClickable(true);
     lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView&lt;?&gt; list, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            alert_editlist(id);
            return true;
        }           
     });
}

@Override
public void onDestroy() {
    super.onDestroy();
    helper.close();
}

@Override
public void onListItemClick(ListView list, View view, int position, long id) {
    Intent i=new Intent(db_list.this, db_new_man.class);

    i.putExtra(ID_EXTRA, String.valueOf(id));
    startActivity(i);
}

private void alert_editlist(final long id) {
    // TODO Auto-generated method stub
    final CharSequence[] items = {"Edit", "Delete"};

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("What do you want to do?");
    builder.setIcon(R.drawable.ic_setting_36);
    builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {

            if (items[item]=="Edit") {
                Intent i=new Intent(db_list.this, db_new_man.class);
                i.putExtra(ID_EXTRA, String.valueOf(id));
                startActivity(i);
            }
            else if(items[item]=="Delete"){
                                    //this is where my app force close
                helper.deleteRow(id);
                model.requery();
            }
            finish();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(this).inflate(R.menu.option, menu);
    return(super.onCreateOptionsMenu(menu));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId()==R.id.add) {
        //startActivity(new Intent(db_list.this, db_new.class));
        alert_db_new();
        return(true);
    }
    return(super.onOptionsItemSelected(item));
}

private void alert_db_new() {
    // TODO Auto-generated method stub
    final CharSequence[] items = {"Auto", "Manual"};

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Use Your Configuration Setting By");
    builder.setIcon(R.drawable.ic_setting_36);
    builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {

            if (items[item]=="Auto") {
                startActivity(new Intent(db_list.this, db_new_auto.class));
            }
            else if(items[item]=="Manual"){
                startActivity(new Intent(db_list.this, db_new_man.class));
            }
            finish();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}



/*
private View.OnClickListener onSave=new View.OnClickListener() {
    public void onClick(View v) {
        helper.insert
        (
                etNama.getText().toString(),
                etKabupaten.getText().toString(),
                etJalan.getText().toString(),
                etLong.getText().toString(),
                etLat.getText().toString(),
                etKeterangan.getText().toString()
        );
        model.requery();

    }
};
*/

class PuraAdapter extends CursorAdapter {
    PuraAdapter(Cursor c) {
        super(db_list.this, c);
    }
    @Override
    public void bindView(View row, Context ctxt, Cursor c) {
        // TODO Auto-generated method stub
        PuraHolder holder=(PuraHolder)row.getTag();

        holder.populateFrom(c, helper);
    }

    @Override
    public View newView(Context ctxt, Cursor c, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater=getLayoutInflater();
        View row=inflater.inflate(R.layout.row, parent, false);
        PuraHolder holder=new PuraHolder(row);

        row.setTag(holder);

        return(row);
    }
}
static class PuraHolder {
    private TextView nama=null;
    private TextView alamat=null;
    private ImageView icon=null;

    PuraHolder(View row) {
        nama=(TextView)row.findViewById(R.id.nama_pura);
        alamat=(TextView)row.findViewById(R.id.jalan);
        icon=(ImageView)row.findViewById(R.id.icon_pura);
    }

    void populateFrom(Cursor c, PuraHelper helper) {
        nama.setText(helper.getNama(c));
        alamat.setText(helper.getJalan(c));
        icon.setImageResource(R.id.icon_pura);
    }
}

 }
</code></pre>

<p>thank you for the attention</p>
