2012-04-10 41 views
1

我一直在我的logcat每次我跑我的代碼,並不能找出如何解決它的時候得到這個。當我更新我得到這個錯誤,我用類似的代碼,當我刪除,並且工作正常。我在更新中使用了斷點,它一直持續到函數結束。我認爲,在startActivityForResult將進入下一個頁面,但事實並非如此。爲startActivityForResult完全相同的代碼在另一個函數錯誤請求。 = numRows行1,爲numColumns = 1

在這裏工作是更新

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); 
} 

這是我在日誌貓

 
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 
+0

你可能要指出哪一行是造成你這個問題。 – erbsman 2012-04-10 17:28:35

+0

我不是100%。我使用了斷點,它一直持續到函數的結尾。 StartActivity沒有進入下一頁,但是在Add函數中使用了相同的StartActivity代碼,並且工作正常 – Aaron 2012-04-10 17:34:31

+0

看起來像「report.java:129」這裏是壞人,是你的代碼?如果是這樣,你可以在上面的內嵌代碼中標記它嗎?應該幫助一下調試這個:D – erbsman 2012-04-10 17:37:54

回答

2

很樂意幫忙, 加入這樣你就可以作爲答案:)

看起來像「report.java:129」標誌是壞人,是你的代碼?如果是這樣,你可以在上面的內嵌代碼中標記它嗎?應該有點幫助與調試這樣的:d - erbsman 2小時前

1

亞倫我有同樣的異常和解決方案是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那是一個關鍵的,否則你就需要更多的時間和難度解決它!

相關問題