Populating a list using an SQLite database [closed]

jthm0138

New Member
I am pretty new in android application development and I am trying to get on of the rows from a SQLite db to show up as a Listactivity, but this is not working and the program terminates unexpectedly. Here is the code:\[code\]package ankur.test.app;import android.app.ListActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.ArrayAdapter;import android.widget.ListView;public class testMenu extends ListActivity{ HotOrNot Infor = new HotOrNot(this); { Infor.open(); } String[] result = Infor.getList(); { Infor.close(); } @Override protected void onCreate(Bundle ankurtestlist) { // TODO Auto-generated method stub super.onCreate(ankurtestlist); setListAdapter(new ArrayAdapter<String>(testMenu.this, android.R.layout.simple_list_item_2, result)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); Object cheese = result[position]; /* try{ Class ourClass = Class.forName("ankur.test.app."+ cheese); Intent ourIntent = new Intent(testMenu.this, ourClass); startActivity(ourIntent); }catch(ClassNotFoundException e){ e.printStackTrace(); }*/ }}\[/code\]and this is the method in another class:\[code\]public String[] getList() { // TODO Auto-generated method stub String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_HOTNESS}; Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); ArrayList name = new ArrayList(); int i = 0; int iName = c.getColumnIndex(KEY_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){ name.add(c.getString(iName)); i++; } String[] result = (String[]) name.toArray(); return result; }\[/code\]Any help would be appreciated.
 
Top