开发者

Error inserting to SQLite

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(SQLiteDatab开发者_Go百科ase.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)

in table it was insert both data but in ddms its shows error. plz help me on this..

``public class DatabaseHelper extends 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

hi balaji i used your code but i got error like this

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)


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


Check the structure of the table.As per my knowledge in your table structure you may used the constraints i.e like foreign key,Integer,varchar(15) etc. At the insertion time your query not satisfies that constraints. So check the table structure and the SQL query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜