对于我的更新,我想使用activityid
,subactivityid
,public int updateSubActivityActivityComment(String comment, int rating, int subActivityId, int activityId, int inspectionId){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_RATING, rating);
contentValues.put(KEY_COMMENT, comment);
return db.updateWithOnConflict(TABLE_INSPECTION, contentValues,KEY_SUB_ACTIVITY_ID+ " = ? "+subActivityId+" AND "+KEY_INSPECTION_ID + " = ? "+inspectionId +" AND "+KEY_ACTIVITY_ID +" = ? "+activityId,new String[]{String.valueOf(subActivityId)} ,SQLiteDatabase.CONFLICT_IGNORE);
}
搜索相关信息,但在调用更新状态时,我会收到此错误。请帮助。
java.lang.IllegalArgumentException: Too many bind arguments. 3 arguments were provided but the statement needs 2 arguments.
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:68)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1574)
at com.theavo.ck_app.DatabaseHelper.updateSubActivityActivityComment(DatabaseHelper.java:264)
at com.theavo.ck_app.FragmentSubInspectionComment.onClick(FragmentSubInspectionComment.java:470)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Log Cat -
<p id="game-info"> </p>
<ul id="levels">
<li class="selected"><a href="javascript:" level="0">1</a></li>
<li><a href="javascript:" level="1">2</a></li>
<li><a href="javascript:" level="2">3</a></li>
<li><a href="javascript:" level="3">4</a></li>
<li><a href="javascript:" level="4">5</a></li>
<li><a href="javascript:" level="5">6</a></li>
<li><a href="javascript:" level="6">7</a></li>
<li><a href="javascript:" level="7">8</a></li>
<li><a href="javascript:" level="8">9</a></li>
<li><a href="javascript:" level="9">10</a></li>
</ul>
<div id="playfield-wrapper"> <div class="win-text">Win</div></div>
<button id="score">Submit</button>
<form id='postscoreform' action="memorygamescore.php" method="get">
<input type='hidden' value='0' id="postscore" name='score' />
</form>
答案 0 :(得分:4)
你应该在这里传递三个值
String[] whereArgs = new String[]{String.valueOf(subActivityId),String.valueOf(inspectionId),String.valueOf(activityId)};
db.updateWithOnConflict(TABLE_INSPECTION, contentValues,KEY_SUB_ACTIVITY_ID+ " = ? "+" AND "+KEY_INSPECTION_ID + " = ? "+" AND "+KEY_ACTIVITY_ID +" = ? ",whereArgs ,SQLiteDatabase.CONFLICT_IGNORE);
答案 1 :(得分:1)
使用updateWithOnConflict
方法将第4个参数作为null
传递,并从第3个参数中删除?
:
db.updateWithOnConflict(TABLE_INSPECTION,contentValues,
KEY_SUB_ACTIVITY_ID+ " = "
+subActivityId+" AND "+KEY_INSPECTION_ID + " = "
+inspectionId +" AND "+KEY_ACTIVITY_ID +" = "
+activityId,null ,SQLiteDatabase.CONFLICT_IGNORE);
因为已经在第3个参数中传递了带有列名的值,所以不需要再次传递它。