Android: display listview data from database after onclick
<p>i have database like this : table pepak, table category, table subcategory
i just want to display category if i click one of the pepak.name
But now if i click one of pepak.name, my app was error and stopped.</p>

<p>Menu.java</p>

<pre><code>public class Menu extends ListActivity{
    protected SQLiteDatabase db;
    protected Cursor cursor;
    protected ListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db = (new DatabaseHelper(this)).getWritableDatabase();
        cursor = db.rawQuery("SELECT _id, name FROM pepak", null);
        adapter = new SimpleCursorAdapter(
        this, 
        R.layout.pepaklist,
        cursor, 
        new String[] {"name"}, 
        new int[] {R.id.name});
        setListAdapter(adapter);
}

public void onListItemClick(ListView parent, View view, int position, long id) {
    Intent intent = new Intent(this, PepakCats.class);
    Cursor cursor = (Cursor) adapter.getItem(position);
    intent.putExtra("PEPAK_ID", cursor.getInt(cursor.getColumnIndex("_id")));
    startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp =  getMenuInflater();
    blowUp.inflate(R.menu.coll_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){

    case R.id.about:
        Intent i = new Intent("com.pepakbahasajawa.ABOUT");
        startActivity(i);
        break;

    case R.id.exit:
        finish();
        break;
    }
return false;
}
</code></pre>

<p>}</p>

<p>PepakCats.java</p>

<pre><code>public class PepakCats extends ListActivity {
    protected Cursor cursor;
    protected ListAdapter adapter;
    protected int pepakId;

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

        pepakId = getIntent().getIntExtra("PEPAK_ID", 0);
        SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();

        Cursor cursor = db.rawQuery(
            "SELECT _id, pepakId, catname FROM category WHERE pepakId = ?", 
        new String[]{""+pepakId}
        );

        adapter = new SimpleCursorAdapter(
            this, 
            R.layout.category_list,
            cursor, 
            new String[] {"catname"}, 
            new int[] {R.id.catname}
        );

        setListAdapter(adapter);
    }
}
</code></pre>
