整数到数据库的字符串

时间:2014-03-24 18:53:59

标签: android sqlite cursor

我已将我的值存储在数据库中,如下所示:

"CREATE TABLE " + 
        ABezoeAdapter.databasetabel + "(" +
        ABezoeAdapter.recordnummer + " INTEGER, " +
        ABezoeAdapter.bezoekrapportnummer + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        ABezoeAdapter.bezoekrapportdatum + " DATETIME NOT NULL, " +
        ABezoeAdapter.herstellingsoort + " VARCHAR(1) NOT NULL, " +

但是这给我提供了以下阅读程序的问题

Cursor c = onzedatabase.query(databasetabel, allekolommen, bezoekrapportnummer + "=?", new String[] {bezoeknummer}, null, null, null);

        int i = 0;
        String data[] = new String[30];
        data = null;
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
            data[i] = c.getString(i);
            Log.i("abezoeadapter gegevenslezenvanbezoeknummer", "bezoeknummer = " + data[2]);
        }

out logcat我认为我遇到了问题,因为我的值存储为整数,字符串,......

logcat的:

03-24 18:36:06.321: E/AndroidRuntime(785): FATAL EXCEPTION: main
03-24 18:36:06.321: E/AndroidRuntime(785): java.lang.RuntimeException: Unable to start activity      ComponentInfo{com.example.deceunincktechniekers/com.example.deceunincktechniekers.bezoekrapporten}:     java.lang.NullPointerException
03-24 18:36:06.321: E/AndroidRuntime(785):  at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.os.Looper.loop(Looper.java:137)
03-24 18:36:06.321: E/AndroidRuntime(785):  at android.app.ActivityThread.main(ActivityThread.java:5041)
03-24 18:36:06.321: E/AndroidRuntime(785):  at java.lang.reflect.Method.invokeNative(Native Method)
03-24 18:36:06.321: E/AndroidRuntime(785):  at java.lang.reflect.Method.invoke(Method.java:511)
03-24 18:36:06.321: E/AndroidRuntime(785):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-24 18:36:06.321: E/AndroidRuntime(785):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-24 18:36:06.321: E/AndroidRuntime(785):  at dalvik.system.NativeStart.main(Native Method)
03-24 18:36:06.321: E/AndroidRuntime(785): Caused by: java.lang.NullPointerException
03-24 18:36:06.321: E/AndroidRuntime(785):  at com.example.deceunincktechniekers.ABezoeAdapter.gegevenslezenvanbezoeknummer(ABezoeAdapter.java:480)
03-24 18:36:06.321: E/AndroidRuntime(785):  at com.example.deceunincktechniekers.bezoekrapporten.opslaan(bezoekrapporten.java:784)

我的不同类型的价值可以解决什么问题 互联网搜索到目前为止没有帮助我

提前致谢

1 个答案:

答案 0 :(得分:3)

String data[] = new String[30];
data = null;

您将data分配给null,然后尝试为其指定值。因此NPE。删除data = null

要处理可变数量的条目,请考虑使用例如ArrayList<String>代替String[]