When I search any value that does not exist in database app crashes instantly.
code from database class
public String ifExistIn(String stationName) {
String query = "SELECT stationName FROM review WHERE stationId" +
"='" + stationName + "' OR " + " stationName " + "='" + stationName + "' LIMIT 1";
try (SQLiteDatabase database = this.getWritableDatabase();
Cursor c = database.rawQuery(query, null)) {
c.moveToFirst();
return c.getString(c.getColumnIndex("stationName"));
}
}
Code from Activity class, it adds available record to the listView
public View.OnClickListener searchStation = new View.OnClickListener() {
@Override
public void onClick(View v) {
String searchString = searchText.getText().toString();
//String useThis = dbHelper.ifExistIn(searchString);
if (list.contains(dbms.ifExistIn(searchString))) {
AlertDialog.Builder builder = new AlertDialog.Builder(SearchAndReview.this);
builder.setTitle("");
builder.setMessage("RECORD ALREADY IN THE LIST ");
builder.setNeutralButton("OK", null);
builder.create().show();
else {
list.add(dbms.ifExistIn(searchString));
listView.setAdapter(arrayAdapter);
}
}
}
};
Aucun commentaire:
Enregistrer un commentaire