Android-android.database.sqlite.SQLiteException:未知错误(代码0):nativeGetBlob中的INTEGER数据

时间:2016-05-02 11:24:28

标签: android sqlite

我正在处理数据库并将数据从数据库导出到xml文件,但我在这行byte[] s = cur.getBlob(idx);中遇到了这个错误。在我使用这条线之前。 String s=cur.getString(idx);。但它也犯了错误。然后我找到了在blob类型中更改它的解决方案。这是我的代码。请给出一些建议或答案。

 private void exportTable(String tableName) throws IOException {
        mExporter.startTable(tableName);

        // get everything from the table
        String sql = "select * from " + tableName;
        Cursor cur = mDb.rawQuery(sql, new String[0]);
        int numcols = cur.getColumnCount();

        cur.moveToFirst();

        // move through the table, creating rows
        // and adding each column with name and value
        // to the row
        while (cur.getPosition() < cur.getCount()) {
            mExporter.startRow();
            String name;
            String val;
            for (int idx = 0; idx < numcols; idx++) {
                name = cur.getColumnName(idx);
                byte[] s = cur.getBlob(idx);
                val=new String(s,"UTF-8");
                mExporter.addColumn(name, val);
            }

            mExporter.endRow();
            cur.moveToNext();
        }

        cur.close();

        mExporter.endTable();
    }

这是错误日志

05-02 16:15:53.417  31609-31609/com.android.lunchernewone E/Launcher.Workspace﹕ Skipping child, screenId 3 not found
05-02 16:15:53.427  31609-31609/com.android.lunchernewone E/Launcher.Workspace﹕ Skipping child, screenId 3 not found
05-02 16:15:57.897  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.android.calendar/com.android.calendar.widget.CalendarTypeAppWidgetProvider} can not fit on this device (1260, 1260)
05-02 16:15:57.897  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.appwidget.clock/com.lge.variousstyle.quickcover.widget.QuickCoverProvider_01} has invalid dimensions (-2, -2)
05-02 16:15:57.907  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.appwidget.clock/com.lge.variousstyle.digitalclock.widget.ClockDigitalWidgetProvider_dual} has invalid dimensions (-2, -2)
05-02 16:15:57.977  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.task/com.lge.task.widget.TasksWidgetProvider} can not fit on this device (1170, 330)
05-02 16:15:57.987  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.sizechangable.weather/com.lge.sizechangable.weather.layout.Weather4x2} can not fit on this device (1200, 480)
05-02 16:15:57.997  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.sizechangable.weather/com.lge.sizechangable.weather.layout.Weather4x1} can not fit on this device (1200, 240)
05-02 16:15:57.997  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.sizechangable.weather/com.lge.sizechangable.weather.layout.WeatherFph} can not fit on this device (30000, 30000)
05-02 16:15:58.007  31609-31609/com.android.lunchernewone E/AppsCustomizePagedView﹕ Widget ComponentInfo{com.lge.sizechangable.worldclock/com.lge.sizechangable.worldclock.WorldClock4X2} can not fit on this device (1104, 438)
05-02 16:16:47.257  31609-31609/com.android.lunchernewone E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.android.lunchernewone, PID: 31609
    android.database.sqlite.SQLiteException: unknown error (code 0): INTEGER data in nativeGetBlob
            at android.database.CursorWindow.nativeGetBlob(Native Method)
            at android.database.CursorWindow.getBlob(CursorWindow.java:399)
            at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:45)
            at com.android.lunchernewone.DatabaseDump.exportTable(DatabaseDump.java:93)
            at com.android.lunchernewone.DatabaseDump.exportData(DatabaseDump.java:62)
            at com.android.lunchernewone.Launcher.getDB(Launcher.java:3021)
            at com.android.lunchernewone.Launcher$20.onClick(Launcher.java:2921)
            at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
            at android.widget.AdapterView.performItemClick(AdapterView.java:299)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:2957)
            at android.widget.AbsListView$3.run(AbsListView.java:3849)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5105)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
            at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

INTEGER data in nativeGetBlob我猜你的答案就在这里

您尝试使用Integer获取getBlob()数据,应该是getInt()

cur.getInt(idx);

答案 1 :(得分:-1)

也许您数据库中的数据是整数类型。因此,您应该关闭Cursor.getInt()。