i am trying to code an app to test activities and database , so far everything has worked , I can view and transit between activities and insert into database , things are fine , but when I select from my sqlite database the app crashes
so here is my DBhelper code for selecting several rows and keep them in an array
public String[] getrow (String name) {
String selectSQL = "select product.[Name] , orders.[Cname] , orders.[Pdate] , orders.[count] from product left join orders on product.[Id]=orders.[ProductId] where orders.[Cname] like ?";
cursor = dataBase.rawQuery(
selectSQL,
new String[] {String.valueOf(name)});
String[] row= new String [5];
int i=0;
while(cursor.moveToNext()){
row[i] = cursor.getString(cursor.getColumnIndex("Name"))+" "+ cursor.getString(cursor.getColumnIndex("Cname"))+" "+ cursor.getString(cursor.getColumnIndex("Pdate"))+" "+ cursor.getString(cursor.getColumnIndex("count"));
i++;
}
return row;
}
and here is the activity where I use it
buttonrep = (Button) findViewById(R.id.buttonrep);
buttonrep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText editrep = (EditText)
findViewById(R.id.editrep);
String name = editrep.getText().toString();
String[] row=new String [5];
row=d.getrow(name);
TextView rowtext1 = (TextView) findViewById(R.id.rowtext1);
rowtext1.setText(row[1]);
TextView rowtext2 = (TextView) findViewById(R.id.rowtext2);
rowtext2.setText(row[2]);
TextView rowtext3 = (TextView) findViewById(R.id.rowtext3);
rowtext3.setText(row[3]);
TextView rowtext4 = (TextView) findViewById(R.id.rowtext4);
rowtext4.setText(row[4]);
TextView rowtext5 = (TextView) findViewById(R.id.rowtext5);
rowtext5.setText(row[5]);
}
});
so basically I want to select several rows and show them in an activity how do I fix the crash bug
Aucun commentaire:
Enregistrer un commentaire