Hi I have a problem with my android application. I want to use a sqlite database for my application and I have one activity with the onCreate(),onPause() and onResume() methods. I have built a class DatenbankManager with the that create a Table id and name but if I start my Application with a Emulator I get a message and my Application close after this.
here my DatenbankManager Class:
package de.tarasov.database_example_tarasov;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatenbankManager extends SQLiteOpenHelper {
private static final String DB_Name = "Stundenplanname.db";
private static final int DB_VERSION = 1;
private static final String KLASSEN_CREATE = "CREATE TABLE Stundenplan(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
"name TEXT NOT NULL";
private static final String KLASSEN_DROP = "DROP TABLE IF EXIST Stundenplan";
//Konstruktor
public DatenbankManager(Context context) {
super(context, DB_Name, null, DB_VERSION);
}
//Methode wenn eine Datenbank erstellt werden muss
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(KLASSEN_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(KLASSEN_DROP); // Löscht Tabelle wenn nicht vorhanden
onCreate(db); //Erstellt Tabelle
}
}
Here my MainActivity:
package de.tarasov.database_example_tarasov;
import android.os.Bundle;
import android.widget.Toast;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
public class MainActivity extends Activity {
private SQLiteDatabase mDatenbank;
private DatenbankManager mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHelper = new DatenbankManager(this);
}
@Override
protected void onPause() {
super.onPause();
mDatenbank.close(); //Schließt Datenbank
Toast.makeText(this,
getResources().getString(R.string.db_close),
Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
mDatenbank = mHelper.getReadableDatabase(); //Datenbank öffnen
//Gibt Kurztext aus
Toast.makeText(this,
getResources().getString(R.string.db_open),
Toast.LENGTH_SHORT).show();
}
}
here is the error message:

and if I make a debug I see:
Source not found.
in LogCat I see this:

I hate this debuger 😀
You forgot
)in your create table statement: