没有这样的列错误代码在使用 4.4 Kitkat 时不起作用

no such column error code doesn't work when using 4.4 Kitkat

我在 android 5 分钟创建了一个应用程序。但我想 运行 在 4.4 android 时创建它。所以我将文件从第一个项目复制到第二个项目并更正了 AndroidManifest.当我编译第一个版本时 evrythink 工作正常,但是在应该使用 android 4.4 的版本上我得到 SQLite exeption "no such column"。 代码:

   public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_select, container, false);
        helper = new MobilnaPytajkaDatabase(getContext());
        db = helper.getWritableDatabase();
        cursor = db.query("QUIZ_TABLE", new String[]{"_id", "QUESTION"},
                "TYPE=0", null, null, null, null, null);
        lista = (ListView) view.findViewById(R.id.listview);
        if(cursor.moveToFirst()) {
            try {
                CursorAdapter ca = new SimpleCursorAdapter(getContext(),
                        R.layout.whitetextlayout1, cursor,
                        new String[]{"QUESTION"}, new int[]{R.id.text1},
                        0);
                lista.setAdapter(ca);
                lista.setOnItemClickListener(listener);
            } catch (SQLiteException e) {
                ;
            }
            return view;
        }
        else
            return inflater.inflate(R.layout.emptylist, container,false);
    }

SQLite 打开助手class:

package com.nieruchalski.mobilnapytajkaforkitkat;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MobilnaPytajkaDatabase extends SQLiteOpenHelper {
    public final static int DB_VERSION = 2;
    public final static String DB_NAME = "QUIZ_DATA";

    MobilnaPytajkaDatabase(Context context)
    {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("CREATE TABLE QUIZ_TABLE (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
        + "QUESTION TEXT"
        + "ANSWER TEXT"
        + "TYPE INTEGER);");
    }
}

Logcat :

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.nieruchalski.mobilnapytajkaforkitkat, PID: 2450
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nieruchalski.mobilnapytajkaforkitkat/com.nieruchalski.mobilnapytajkaforkitkat.selectQuiz}: android.database.sqlite.SQLiteException: no such column: TYPE (code 1): , while compiling: SELECT _id, QUESTION FROM QUIZ_TABLE WHERE TYPE=0
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2509)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569)
                      at android.app.ActivityThread.access0(ActivityThread.java:150)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:168)
                      at android.app.ActivityThread.main(ActivityThread.java:5885)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
                   Caused by: android.database.sqlite.SQLiteException: no such column: TYPE (code 1): , while compiling: SELECT _id, QUESTION FROM QUIZ_TABLE WHERE TYPE=0
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:921)
                      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:532)
                      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                      at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
                      at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:68)
                      at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1402)
                      at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1249)
                      at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1120)
                      at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1326)
                      at com.nieruchalski.mobilnapytajkaforkitkat.selectFragment.onCreateView(selectFragment.java:38)
                      at android.app.Fragment.performCreateView(Fragment.java:2238)
                      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:977)
                      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1152)
                      at android.app.BackStackRecord.run(BackStackRecord.java:793)
                      at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1539)
                      at android.app.FragmentController.execPendingActions(FragmentController.java:325)
                      at android.app.Activity.performStart(Activity.java:6278)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2472)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2569) 
                      at android.app.ActivityThread.access0(ActivityThread.java:150) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:168) 
                      at android.app.ActivityThread.main(ActivityThread.java:5885) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 

真的与 Kitkat 无关。您只是在 MobilnaPytajkaDatabase#onCreate() 中的列规范之间缺少逗号 ,。将它们添加到那里并卸载您的应用程序以删除旧数据库并创建一个新数据库。