Hey Leute,
ich schreibe an einer simplen Datenbankapplikation, nur wirft mit meine app immer wieder den Fehler entgegen, dass meine Applikation "stopped unexpected"...
hier mal mein code:
package org.madmax.event;
import static org.madmax.event.Constants.TABLE_NAME;
import static org.madmax.event.Constants.TIME;
import static org.madmax.event.Constants.TITLE;
import static android.provider.BaseColumns._ID;
import or.madmax.events.R;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;
public class EventsActivity extends Activity {
private EventsData events;
private static String[] FROM = { _ID, TIME, TITLE, };
private static String ORDER_BY = TIME + "DESC";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
events = new EventsData(this);
try {
addEvent("Hello World DB");
Cursor cursor = getEvents();
showEvents(cursor);
} finally {
events.close();
}
}
private void addEvent(String string) {
SQLiteDatabase db = events.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TIME, System.currentTimeMillis());
values.put(TITLE, string);
db.insertOrThrow(TABLE_NAME, null, values);
}
private Cursor getEvents() {
SQLiteDatabase db = events.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY);
startManagingCursor(cursor);
return cursor;
}
private void showEvents(Cursor cursor) {
StringBuilder builder = new StringBuilder("Saved events:\n");
while(cursor.moveToNext()){
long id = cursor.getLong(0);
long time = cursor.getLong(1);
String title = cursor.getString(2);
builder.append(id).append(": ");
builder.append(time).append(": ");
builder.append(title).append("\n");
}
TextView text = (TextView) findViewById(R.id.text);
text.setText(builder);
}
}
Alles anzeigen
package org.madmax.event;
import static android.provider.BaseColumns._ID;
import static org.madmax.event.Constants.TABLE_NAME;
import static org.madmax.event.Constants.TIME;
import static org.madmax.event.Constants.TITLE;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class EventsData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "events.db";
private static final int DATABASE_VERSION = 1;
public EventsData(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY, "
+ TIME + " INTEGER, " + TITLE + " TEXT NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
Alles anzeigen
package org.madmax.event;
import android.provider.BaseColumns;;
public interface Constants extends BaseColumns {
public static final String TABLE_NAME = "events";
//columns in the events db
public static final String TIME = "time";
public static final String TITLE = "title";
}
Alles anzeigen
der Error lautet:
ZitatAlles anzeigen04-14 18:03:01.834: D/AndroidRuntime(367): Shutting down VM
04-14 18:03:01.864: W/dalvikvm(367): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-14 18:03:01.954: E/AndroidRuntime(367): FATAL EXCEPTION: main
04-14 18:03:01.954: E/AndroidRuntime(367): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{or.madmax.events/org.madmax.events.EventsActivity}: java.lang.ClassNotFoundException: org.madmax.events.EventsActivity in loader dalvik.system.PathClassLoader[/data/app/or.madmax.events-2.apk]
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.os.Looper.loop(Looper.java:123)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-14 18:03:01.954: E/AndroidRuntime(367): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 18:03:01.954: E/AndroidRuntime(367): at java.lang.reflect.Method.invoke(Method.java:521)
04-14 18:03:01.954: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-14 18:03:01.954: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-14 18:03:01.954: E/AndroidRuntime(367): at dalvik.system.NativeStart.main(Native Method)
04-14 18:03:01.954: E/AndroidRuntime(367): Caused by: java.lang.ClassNotFoundException: org.madmax.events.EventsActivity in loader dalvik.system.PathClassLoader[/data/app/or.madmax.events-2.apk]
04-14 18:03:01.954: E/AndroidRuntime(367): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-14 18:03:01.954: E/AndroidRuntime(367): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-14 18:03:01.954: E/AndroidRuntime(367): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-14 18:03:01.954: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-14 18:03:01.954: E/AndroidRuntime(367): ... 11 more
Irgendwie seh ich den Fehler ned...
Wäre SEHR SEHR dankbar für eure Hilfe
glg