Android java.lang.IllegalArgumentException:索引2处的绑定值为null
只是想知道,对于少数Android设备,我们会遇到以下提到的例外情况:Android java.lang.IllegalArgumentException:索引2处的绑定值为null,android,sqlite,illegalargumentexception,Android,Sqlite,Illegalargumentexception,只是想知道,对于少数Android设备,我们会遇到以下提到的例外情况: Caused by: java.lang.IllegalArgumentException: the bind value at index 2 is null at net.sqlcipher.database.SQLiteProgram.bindString(SourceFile:237) at net.sqlcipher.database.SQLiteDatabase.updateWithOnConflict
Caused by: java.lang.IllegalArgumentException: the bind value at index 2 is
null
at net.sqlcipher.database.SQLiteProgram.bindString(SourceFile:237)
at net.sqlcipher.database.SQLiteDatabase.updateWithOnConflict
(SourceFile:1794)
at net.sqlcipher.database.SQLiteDatabase.update(SourceFile:1730)
at com.sample.android.SQDBHelper.onUpgrade(SourceFile:276)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase
(SourceFile:123)
at com.sample.android.SQDBController.read(SourceFile:431)
at com.sample.android.ui.MainActivity.onCreate(SourceFile:42)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity
示例代码
ContentValues contentValues = new ContentValues();
contentValues.put("COL_VALUE1", value1);
contentValues.put("COL_VALUE2", value2);
contentValues.put("COL_VALUE3", value3);
contentValues.put("COL_VALUE4", value4);
contentValues.put("COL_VALUE5", value5);
database.insert(DATA_TABLE, null, contentValues);
的确,绑定值2是一个空值,我们可以处理它。然而,我想知道为什么在大多数设备中我们没有观察到上述异常。可能是您的应用程序活动被Android操作系统杀死,当它从savedInstanceState重建时,它没有处于正确的状态 当用户使用“主页”按钮切换到另一个应用程序时,可能会发生这种情况,直到退出应用程序后才会返回。当你的应用在后台时,操作系统会破坏你的应用活动。 用户切换回应用程序后,将从savedInstanceState重新创建活动
要模拟此场景,您可以使用“设置”>“开发人员选项”>“选中“不保留活动”选项,并在屏幕上使用“主页”按钮测试您的应用程序,然后继续运行您的应用程序,查看是否可以复制它。如果不查看您的代码和完整的日志,请查看回复。我们尝试了相同的方法,但无法重现可以得到上述异常的场景。我们从Google play得到的这些例外。我们的问题类似于[