I am quite new to android and have been reading a bit, also I am working on little programs of my own to get a feel. I am stumped by what seems to be a little error. In my app, data is loaded into a listview and when I click a row, I am supposed to use that row 'text' to query my database and display the results in a new activity.
The name of my row is passed to the new activity but I am not able to get the query results back and I actually get an error on
txtHolder.setText(dbHeplper.getNumber(name));
of Attempt to invoke virtual method 'java.lang.String on a null reference.
I am trying to select NAME from the TABLE where the TEXT of the listview is the same as what is in the table...so no idea why it should be null.
this is my Second activity Class
public class SingleListItem extends Activity{
TextView txtName;
TextView txtHolder;
DatabaseHelper dbHeplper;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
txtName= (TextView) findViewById(R.id.txtName);
txtHolder=(TextView)findViewById(R.id.txtEmail);
Intent i=getIntent();
String name = i.getStringExtra("product");
txtName.setText(name);
// Toast.makeText(getBaseContext(),"test",Toast.LENGTH_LONG).show();
txtHolder.setText(dbHeplper.getNumber(name));
}
}
and the DatabaseHelper class which query my database (well part of it)
public class DatabaseHelper extends SQLiteOpenHelper {
public static String DB_PATH = "/data/data/com.pc.sqlitedemo/databases/";
public static String DB_NAME = "Test.sqlite";
public static final int DB_VERSION = 2;
public static String Column_name="NAME";
public static final String TB_USER = "Users";
private SQLiteDatabase myDB;
private Context context;
public String getNumber(String who){
String selectQuery = "SELECT name FROM " + TB_USER + "WHERE NAME = "+ Column_name ;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
String[] data = null;
if (cursor.moveToFirst()) {
do {
} while (cursor.moveToNext());
}
db.close();
return who;
//return data;
}
Aucun commentaire:
Enregistrer un commentaire