1.android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
原因:使用cursor对象前未将指针移至开头
解决方法:需要先将指针移到开头位置:加上cursor.moveToFirst();
2.java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
得到的数据列数需要与corsur.getString(id)中的id对应。上面超出了列数
3.java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
得到的数据中,访问了空的数据
4.java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
数据库没有打开,SQLiteDatabase db;中db为空,db.execSQL()执行错误
需要对db赋值,如:
dbHelper= new DBHelper(MainActivity.this,"info.db",null,1);
db=dbHelper.getWritableDatabase();
5. android.content.ActivityNotFoundException: Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml?
该错误是没有在配置文件定义这个activity。
需要在AndroidManifest.xml文件中添加activity
<activity android:name=".ListMenuActivity"></activity>
或
<activity android:name="com.example.MyApplication.ListMenuActivity"></activity>
6.Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @2b79f764
Java版本与Gradle版本不匹配;
解决方法:settings->Build,Execution->Build Tools->Gradle中修改Java版本。
Java版本与Gradle版本匹配目录:
解决办法二:打开Android项目下的gradle/wrapper/gradle-wrapper.properties文件修改Gradle版本,Java 17版本最低需要7.2版本的Gradle。
7.java.lang.UnsatisfiedLinkError: dlopen failed: library "libBaiduMapSDK_base_v7_5_9.so" not found
found lib armeabi/BaiduMapSDK_base_v7_5_9.so error,将so文件复制到app->libs->armabi文件夹中。
因为Android Studio导入.so文件有两种方式,如果直接在libs目录下创建子目录armeabi放置.so文件,那么就必须在build.gradle中添加sourceSets {...}语句。