2011-09-01 88 views
0
09-01 14:59:09.177: ERROR/Database(5654): **Error inserting GuestName=q** 
09-01 14:59:09.177: ERROR/Database(5654): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed 
09-01 14:59:09.177: ERROR/Database(5654):  at android.database.sqlite.SQLiteStatement.native_execute(Native Method) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410) 
09-01 14:59:09.177: ERROR/Database(5654):  at com.ezee.app.DatabaseHelper.AddFeedback(DatabaseHelper.java:164) 
09-01 14:59:09.177: ERROR/Database(5654):  at com.ezee.app.user.Btn_Addfeedback(user.java:122) 
09-01 14:59:09.177: ERROR/Database(5654):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-01 14:59:09.177: ERROR/Database(5654):  at java.lang.reflect.Method.invoke(Method.java:521) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.view.View$1.onClick(View.java:2067) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.view.View.performClick(View.java:2408) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.view.View$PerformClick.run(View.java:8816) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.os.Handler.handleCallback(Handler.java:587) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.os.Handler.dispatchMessage(Handler.java:92) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.os.Looper.loop(Looper.java:123) 
09-01 14:59:09.177: ERROR/Database(5654):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
09-01 14:59:09.177: ERROR/Database(5654):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-01 14:59:09.177: ERROR/Database(5654):  at java.lang.reflect.Method.invoke(Method.java:521) 
09-01 14:59:09.177: ERROR/Database(5654):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
09-01 14:59:09.177: ERROR/Database(5654):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
09-01 14:59:09.177: ERROR/Database(5654):  at dalvik.system.NativeStart.main(Native Method) 
09-01 14:59:09.206: ERROR/Database(5654): **Error inserting GuestName=q Address=w** 
09-01 14:59:09.206: ERROR/Database(5654): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed 
09-01 14:59:09.206: ERROR/Database(5654):  at android.database.sqlite.SQLiteStatement.native_execute(Native Method) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410) 
09-01 14:59:09.206: ERROR/Database(5654):  at com.ezee.app.DatabaseHelper.AddFeedback(DatabaseHelper.java:166) 
09-01 14:59:09.206: ERROR/Database(5654):  at com.ezee.app.user.Btn_Addfeedback(user.java:122) 
09-01 14:59:09.206: ERROR/Database(5654):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-01 14:59:09.206: ERROR/Database(5654):  at java.lang.reflect.Method.invoke(Method.java:521) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.view.View$1.onClick(View.java:2067) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.view.View.performClick(View.java:2408) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.view.View$PerformClick.run(View.java:8816) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.os.Handler.handleCallback(Handler.java:587) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.os.Handler.dispatchMessage(Handler.java:92) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.os.Looper.loop(Looper.java:123) 
09-01 14:59:09.206: ERROR/Database(5654):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
09-01 14:59:09.206: ERROR/Database(5654):  at java.lang.reflect.Method.invokeNative(Native Method) 
09-01 14:59:09.206: ERROR/Database(5654):  at java.lang.reflect.Method.invoke(Method.java:521) 
09-01 14:59:09.206: ERROR/Database(5654):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
09-01 14:59:09.206: ERROR/Database(5654):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
09-01 14:59:09.206: ERROR/Database(5654):  at dalvik.system.NativeStart.main(Native Method) 

表中它插入了兩個數據,但在ddms中顯示錯誤。 PLZ幫我在這..插入到SQLite時出錯

``公共類DatabaseHelper擴展SQLiteOpenHelper {

static final String dbName = "feedback"; 
static final String quetypetable = "Question"; 
static final String colquetypeID ="QuestiontypeID"; 
static final String colquetype = "Questiontype"; 

static final String anstypetable ="Answer"; 
static final String colanstypeID = "AnswertypeID"; 
static final String colansTYPE = "Answertype"; 

static final String questiontable = "Mainquestions"; 
static final String colqueID = "QuestionID"; 
static final String colqueName = "QuestionName"; 
static final String colQue = "Questiontypeid"; 
static final String colans = "Answertypeid"; 

static final String feedbacktable = "Feedback"; 
static final String colfeedbackId = "FeedbackId"; 
static final String colguestname = "GuestName"; 
static final String coladdress = "Address"; 
static final String colphone = "Phone"; 
static final String colemail = "Email"; 
static final String colsuggestion = "suggestion"; 
static final String colgrievances = "grievances"; 



public DatabaseHelper(Context context) { 
    super(context, dbName, null,33); 

    // TODO Auto-generated constructor stub 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
     // TODO Auto-generated method stub 

    db.execSQL("CREATE TABLE "+quetypetable+" ("+colquetypeID+ " INTEGER PRIMARY KEY , "+colquetype+ " TEXT)"); 

    db.execSQL("CREATE TABLE "+anstypetable+" ("+colanstypeID+ " INTEGER PRIMARY KEY , "+colansTYPE+ " TEXT)"); 

    db.execSQL("CREATE TABLE "+questiontable+" ("+colqueID+" INTEGER PRIMARY KEY ,"+colqueName+" text,"+colQue+" integer NOT NULL REFERENCES "+quetypetable+" ("+colquetypeID+"),"+colans+" integer NOT NULL REFERENCES "+anstypetable+" ("+colanstypeID+"))"); 

    db.execSQL("CREATE TABLE "+feedbacktable+"("+colfeedbackId+" INTEGER PRIMARY KEY,"+colguestname+" text NOT NULL,"+coladdress+" text NOT NULL,"+colphone+" text NOT NULL,"+colemail+" text NOT NULL,"+colsuggestion+" text NOT NULL,"+colgrievances+" text NOT NULL)"); 




     } 



    @Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    // TODO Auto-generated method stub 

} 


    public void AddFeedback(String gname, String add, String mail, 
      String phn, String sugg, String gre) { 
     // TODO Auto-generated method stub 
     SQLiteDatabase db = this.getWritableDatabase(); 
     ContentValues cv = new ContentValues(); 

     cv.put(colguestname,gname); 
     db.insert(feedbacktable, colguestname, cv); 
     cv.put(coladdress, add); 
     db.insert(feedbacktable, coladdress, cv);   
     cv.put(colphone, phn); 
     db.insert(feedbacktable, colphone, cv); 
     cv.put(colemail, mail); 
     db.insert(feedbacktable, colemail, cv); 
     cv.put(colsuggestion, sugg); 
     db.insert(feedbacktable, colsuggestion, cv); 
     cv.put(colgrievances,gre); 
     db.insert(feedbacktable, colgrievances, cv); 
     db.close(); 
    } 

} i called function AddFeedback.at insert time

喜巴拉吉我用了你的代碼,但我得到的錯誤是這樣

09-02 11:26:49.169: ERROR/AndroidRuntime(8248): FATAL EXCEPTION: main 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): java.lang.IllegalStateException: Could not execute method of the activity 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.view.View$1.onClick(View.java:2072) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.view.View.performClick(View.java:2408) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.view.View$PerformClick.run(View.java:8816) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.os.Handler.handleCallback(Handler.java:587) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.os.Handler.dispatchMessage(Handler.java:92) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.os.Looper.loop(Looper.java:123) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at java.lang.reflect.Method.invokeNative(Native Method) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at java.lang.reflect.Method.invoke(Method.java:521) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at dalvik.system.NativeStart.main(Native Method) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): Caused by: java.lang.reflect.InvocationTargetException 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at com.ezee.app.user.Btn_Addfeedback(user.java:114) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at java.lang.reflect.Method.invokeNative(Native Method) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at java.lang.reflect.Method.invoke(Method.java:521) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at android.view.View$1.onClick(View.java:2067) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): ... 11 more 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): Caused by: java.lang.NullPointerException 09-02 11:26:49.169: ERROR/AndroidRuntime(8248): at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298) 09-02 11:26:49.169: ERROR/AndroidRuntime(8248)

+0

你能提供代碼插入數據的地方嗎? – user370305

+0

user370305我的帖子代碼 – Piyush

回答

1
public void AddFeedback(String gname, String add, String mail, 
     String phn, String sugg, String gre) { 
    // TODO Auto-generated method stub 
    SQLiteDatabase db = this.getWritableDatabase(); 
    ContentValues cv = new ContentValues(); 

    cv.put(colguestname,gname); 
    cv.put(coladdress, add); 
    cv.put(colphone, phn); 
    cv.put(colemail, mail); 
    cv.put(colsuggestion, sugg); 
    cv.put(colgrievances,gre); 
    db.insert(feedbacktable, null, cv); 
    db.close(); 
} 
+0

balaji我轉到natvie方法onclick listner和它會work.its不打電話addfeddback方法..Thanx balaji :) – Piyush

0

檢查表的結構。根據我的知識在你的表結構中可以使用約束,例如外鍵,Integer,varchar(15)等。在插入時,你的查詢不滿足約束。所以檢查表結構和SQL查詢。

+0

什麼是你的插入查詢? –

+0

balaji我的職位代碼看到它,並告訴我你的表中指定約束爲'NOT NULL'.soso – Piyush

+0

.so在最後一行調用插入方法意味着db.close()之前的意思。 –