字段0,-1的错误请求。 numRows = 1,numColumns = 1

时间:2012-04-10 16:52:57

标签: android database sqlite runtime-error

每次运行代码时,我都会在我的logcat中得到这个,并且无法弄清楚如何修复它。当我更新我得到这个错误,我删除时使用类似的代码,并且工作正常。我在更新时使用了断点,它一直在功能结束。我认为在startActivityForResult会转到下一页,但事实并非如此。 startActivityForResult完全相同的代码在另一个函数

中工作

以下是更新的代码

    public void edit_to_report_page(final View v) {

    LayoutInflater inflater = LayoutInflater.from(this);
    View addView = inflater.inflate(R.layout.new_vehicle, null);
    idNum = (EditText) addView.findViewById(R.id.deleteRecord);
    new AlertDialog.Builder(this)
            .setTitle("Edit a report")
            .setMessage("Enter the Id number of the report to edit")
            .setView(addView)
            .setPositiveButton("Edit",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {
                            String id = idNum.getText().toString();
                            uniqueID = Long.parseLong(id);
                            newID(uniqueID);
                            info.open();

                            try {
                                boolean correctNumber = info
                                        .Exists(uniqueID);
                                if (!correctNumber) {
                                    Toast.makeText(getApplicationContext(),
                                            "Number not found",
                                            Toast.LENGTH_SHORT).show();

                                    info.close();

                                }else{

                                    info.close();
                                    intent = new Intent(v.getContext(),
                                            report.class);
                                    startActivityForResult(intent, 0);
                                }
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub

                        }
                    }).show();

}

以下是适用于删除的代码

public void delete_db(View v) {

    LayoutInflater inflater = LayoutInflater.from(this);
    View addView = inflater.inflate(R.layout.new_vehicle, null);
    idNum = (EditText) addView.findViewById(R.id.deleteRecord);
    final Dialog d = new Dialog(this);
    final TextView tv = new TextView(this);

    new AlertDialog.Builder(this)
            .setTitle("Delete a report")
            .setMessage("Enter the Id number of the report to delete")
            .setView(addView)
            .setPositiveButton("Delete",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {
                            String id = idNum.getText().toString();
                            long primaryId = Long.parseLong(id);
                            info.open();
                            try {
                                boolean inCorrectNumber = info
                                        .deleteInspection(primaryId);
                                if (inCorrectNumber) {
                                    Toast.makeText(getApplicationContext(),
                                            "Number not found",
                                            Toast.LENGTH_SHORT).show();

                                }
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            info.close();
                            dbInfo();
                        }
                    })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub

                        }
                    }).show();
}

以下是我的dbAdapter中用于删除和存在(更新)的代码

public boolean Exists(long _id)throws Exception
{

    Cursor c = db.query(DB_TABLE, new String[] { KEY_ROWID},
            "_id=" + _id, null, null, null, null);
     boolean exists=(c.getCount()>0);
    c.close();
    return exists;
}

public boolean deleteInspection(long _id)throws Exception
{
    int numResults = 0;
    numResults = db.delete(DB_TABLE,"_id=" + _id , null);
    return (numResults < 1);
}

这是我在logcat中得到的东西

04-10 09:47:05.006: E/CursorWindow(2961): Bad request for field slot 0,-1. numRows = 1, numColumns = 1
04-10 09:47:05.016: D/AndroidRuntime(2961): Shutting down VM
04-10 09:47:05.027: W/dalvikvm(2961): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-10 09:47:05.046: E/AndroidRuntime(2961): FATAL EXCEPTION: main
04-10 09:47:05.046: E/AndroidRuntime(2961): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.signalsetapp/com.signalsetapp.inspectionchecklist.report}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.os.Looper.loop(Looper.java:123)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at java.lang.reflect.Method.invoke(Method.java:521)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at dalvik.system.NativeStart.main(Native Method)
04-10 09:47:05.046: E/AndroidRuntime(2961): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.database.CursorWindow.getString_native(Native Method)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.database.CursorWindow.getString(CursorWindow.java:329)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at com.signalsetapp.inspectionchecklist.report.getInfoFromDB(report.java:129)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at com.signalsetapp.inspectionchecklist.report.onCreate(report.java:111)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-10 09:47:05.046: E/AndroidRuntime(2961):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-10 09:47:05.046: E/AndroidRuntime(2961):     ... 11 more

2 个答案:

答案 0 :(得分:2)

很高兴帮忙, 添加,以便您可以标记为答案:)

看起来像“report.java:129”这里的坏人,是你的代码吗?如果是这样,你能否在上面的内联代码中标记它。应该帮助调试一下这个:D - erbsman 4小时前

答案 1 :(得分:1)

Aaron我有相同的异常,解决方案是Check your column name you want to access it from cursor is same name as exists in database。同时删除white space并首先尝试在SQLITE browser中查询,然后尝试编码并制作一些Debugging ,I mean print query in logcat and copy ,and paste and sqlite Browser那个一把钥匙,否则你需要花费更多的时间和精力来解决它!