I have an Activity called Wartung. In this Activity are textfields which should be auto filled by database content. Writing to the DB table works but reading from it doesn't. I didn't get any errors or warnings in LogCat.
In the method Wartung.getWartungsDaten(String serienNr) I call the method of the helper class DBController.getLetzterWartungsDaten(String serienNr). The last one does a rawquery to the DB.
To test which parts of the code are executed, ich make a toast("1") which is showed, also toast("2") , but toast("3") isn't. The problem must be in the line "Cursor wartungsCursor = this.dbHelper.getLetzteWartungsDaten(serienNr);" or in the helper class respectively in the method getLetzteWartungsDaten().
Here is my class Wartung:
public class Wartung extends Activity {
private DBController dbHelper;
private SQLiteDatabase db;
private EditText serienNr;
private EditText datum;
private EditText zeit;
private EditText benutzer;
private EditText beschreibung;
private EditText statusAktuell;
private Spinner statusNeu;
private Button buttonAendern;
private LinearLayout layoutStatusAktuell;
private LinearLayout layoutStatusNeu;
private String sSerienNr;
private String sArtikelId;
private String sDatum;
private String sZeit;
private String sBenutzer;
private String sStatus;
private String sBeschreibung;
private List<String> statusListe;
private List<String> listeWartungSerienNr;
private List<String> listeWartungDatum;
private List<String> listeWartungZeit;
private List<String> listeWartungBenutzer;
private List<String> listeWartungStatus;
private List<String> listeWartungBeschreibung;
private boolean editModus = false;
private boolean gespeichert = false;
private int statusPosition = -1;
/**
* Initialisierung aller Objekte
*
*/
private void initObjekte() {
this.serienNr = (EditText) this.findViewById(R.id.editText_wartung_content_serienNr);
this.datum = (EditText) this.findViewById(R.id.editText_wartung_content_datum);
this.zeit = (EditText) this.findViewById(R.id.editText_wartung_content_zeit);
this.benutzer = (EditText) this.findViewById(R.id.editText_wartung_content_benutzer);
this.statusAktuell = (EditText) this.findViewById(R.id.editText_wartung_content_aktueller_status);
this.statusNeu = (Spinner) this.findViewById(R.id.spinner_wartung_content_neuer_status);
this.layoutStatusAktuell = (LinearLayout) this.findViewById(R.id.linearLayoutStatusAktuell);
this.layoutStatusNeu = (LinearLayout) this.findViewById(R.id.linearLayoutStatusNeu);
this.listeWartungSerienNr = new ArrayList<String>();
this.listeWartungDatum = new ArrayList<String>();
this.listeWartungZeit = new ArrayList<String>();
this.listeWartungBenutzer = new ArrayList<String>();
this.listeWartungStatus = new ArrayList<String>();
this.listeWartungBeschreibung = new ArrayList<String>();
this.sArtikelId = new String();
this.sDatum = new String();
this.sZeit = new String();
this.sBenutzer = new String();
this.sStatus = new String();
this.sBeschreibung = new String();
this.statusListe = new ArrayList<String>();
setStatusInSpinner();
this.beschreibung = (EditText) this.findViewById(R.id.editTextMultiLine_wartung_content_aenderung);
}
public void toast(String text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
/**
*
* @param serienNr
*/
private void getWartungsDaten(String serienNr) {
this.dbHelper = new DBController(this);
this.db = this.dbHelper.getReadableDatabase();
toast("1");
// Cursor auswerten
try {
toast("2");
Cursor wartungsCursor = dbHelper.getLetzteWartungsDaten(serienNr);
toast("3");
// Daten zerlegen
if (wartungsCursor != null) {
if (wartungsCursor.moveToFirst()) {
do {
this.listeWartungDatum.add(wartungsCursor.getString(wartungsCursor.getColumnIndexOrThrow(DBController.KEY_DATUM)));
this.listeWartungZeit.add(wartungsCursor.getString(wartungsCursor.getColumnIndexOrThrow(DBController.KEY_ZEIT)));
} while (wartungsCursor.moveToNext());
}
}
// String result = "result: " + this.sSerienNr + " " + this.sDatum + " " + this.sZeit + " " + this.sBenutzer + " " + this.sStatus + " " + this.sBeschreibung;
String result = "result: " + this.listeWartungDatum.get(0).toString() + " " + this.listeWartungZeit.get(0).toString();
toast("Erhaltene Daten: " + result);
} catch (Exception e) {
;
} finally {
this.db.close();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_wartung);
this.setupActionBar();
initObjekte();
setObjekteReadable();
// Zu Testzwecken wird immer der erste Artikel aus der Datenbank ausgewählt
getWartungsDaten("SerienNr 0000");
}
}
And here is my Helper class DBController:
public Cursor getLetzteWartungsDaten(String serienNr) {
this.db = this.getReadableDatabase();
// Filter-String um die anhängenden Daten über die SerienNr zu bekommen
String serienNrFilter = "SELECT " +
DBController.TABLE_WARTUNG + "." + DBController.KEY_DATUM + ", " +
DBController.TABLE_WARTUNG + "." + DBController.KEY_ZEIT + ", " +
"FROM " + DBController.TABLE_WARTUNG
"ORDER BY " + DBController.KEY_DATUM + " DESC," + DBController.KEY_ZEIT + " DESC" + ")";
return db.rawQuery(serienNrFilter, /*new String[] { serienNr }*/null);
}
I have some other methods with reading methods but only this one doesn't work and I don't know why.
I hope you can help me. Thanks!