0

これが私のログファイルです:

05-04 09:29:10.968: E/SQLiteLog(26491): (1) no such column: datum
05-04 09:29:10.968: D/AndroidRuntime(26491): Shutting down VM
05-04 09:29:10.968: W/dalvikvm(26491): threadid=1: thread exiting with uncaught exception (group=0x40edc930)
05-04 09:29:10.976: E/AndroidRuntime(26491): FATAL EXCEPTION: main
05-04 09:29:10.976: E/AndroidRuntime(26491): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.unserekinder/com.example.unserekinder.MainActivity}: android.database.sqlite.SQLiteException: no such column: datum (code 1): , while compiling: SELECT name, datum, geschlecht FROM kind
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.os.Looper.loop(Looper.java:137)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread.main(ActivityThread.java:5041)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at java.lang.reflect.Method.invokeNative(Native Method)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at java.lang.reflect.Method.invoke(Method.java:511)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at dalvik.system.NativeStart.main(Native Method)
05-04 09:29:10.976: E/AndroidRuntime(26491): Caused by: android.database.sqlite.SQLiteException: no such column: datum (code 1): , while compiling: SELECT name, datum, geschlecht FROM kind
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at com.example.unserekinder.DBHelper.select(DBHelper.java:80)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at com.example.unserekinder.MainActivity.listview_fuellen(MainActivity.java:52)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at com.example.unserekinder.MainActivity.onCreate(MainActivity.java:27)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.Activity.performCreate(Activity.java:5104)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-04 09:29:10.976: E/AndroidRuntime(26491):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-04 09:29:10.976: E/AndroidRuntime(26491):    ... 11 more

この問題に関する他のいくつかの質問を読みましたが、何も役に立ちませんでした。この 1 つの列だけが作成されていないように思えます。

private static final String TAG = DBHelper.class.getSimpleName();
    private static final String DATABASE_NAME = "unserekinder.db";
    private static final int DATABASE_VERSION = 2;

    public static final String id = "_id";
    public static final String TABLE_NAME_Kind="kind";
    public static final String NAME = "name";
    public static final String DATUM = "datum";
    public static final String GESCHLECHT = "geschlecht";

    private static final String TABLE_KIND_CREATE = "CREATE TABLE " + TABLE_NAME_Kind + " (" + id + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
    + NAME + " TEXT, " + DATUM + " TEXT, " + GESCHLECHT + " TEXT);";



    public static final String TABLE_KIND_DROP = "DROP TABLE IF EXISTS kind";
    public static final String TABLE_KIND_DELETE = "DELETE TABLE IF EXISTS kind";       

    public DBHelper(Context context){
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_KIND_CREATE);

    }

ご覧のとおり、ステートメントは にあるため、実行する必要がありますonCreate

これが私の選択ステートメントです:

public void insert( String name, String datum, String geschlecht){
        long rowId = -1;
        try{

            SQLiteDatabase db = getWritableDatabase();
            db.beginTransaction();
            ContentValues cv = new ContentValues();

            cv.put(NAME, name);
            cv.put(DATUM, datum);
            cv.put(GESCHLECHT, geschlecht);

            rowId = db.insert(TABLE_NAME_Kind, null, cv);
            db.endTransaction();
        }
        catch (SQLiteException e){
            Log.e(TAG, "insert()", e);
        }
        finally{
            Log.d(TAG, "insert(): rowId=" + rowId);
        }
    }

    public void create(){
        SQLiteDatabase db = getWritableDatabase();
        db.execSQL(TABLE_KIND_CREATE);
    }

    public Cursor select(){
        SQLiteDatabase db = getReadableDatabase();
        db.beginTransaction();
        Cursor cursor = db.query(TABLE_NAME_Kind, new String[] {"name", "datum", "geschlecht"}, 
                "" + "", null, null, null, null);
        db.endTransaction();
        return cursor;
    }

編集:

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(TAG, "Upgrade der Datenbank von Version " + oldVersion + "zu " +newVersion+ "; alle Daten werden gelöscht");
    db.execSQL(TABLE_KIND_DROP);
    onCreate(db);
}
4

1 に答える 1

0

Cursor cursor = db.query(TABLE_NAME_Kind, new String[] {"name", "datum", "geschlecht"}, "" + "", null, null, null, null); クエリが間違っています。次のコードとはどういう意味ですか? "" + "" ""+"" を null に変更できます。試してみてください。

于 2013-11-14T15:38:41.010 に答える