我尝试从 sql 表中仅选择要在列表视图中显示的具有相同模块的文件。如果我使用 if (module == smodule) 应用程序没问题,但 if 语句被跳转,使用 if (module.equals(smodule)) 应用程序正在崩溃。
谢谢@Nambari 问题是我在数据库中的模块值有一个空值。
感谢@Buhake Sindi 的建议'像 String module = ""' 一样实例化它
Java 代码........
private void getFiles() { //getting data from the SQL database
String[] columns = {"id", "file", "module", "date", "note"};
database = helper.getWritableDatabase();
Cursor cursor = database.query("files", columns, null, null, null, null, null);
cursor.moveToFirst();
files.clear();
while (!cursor.isAfterLast()) {
String module = cursor.getString(2);
String smodule = "Alllllll";
Log.v("test", smodule+" "+module+" <-if m=sm getting sql data /not if");
if (module.equals(smodule)){
String file = cursor.getString(1);
files.add(file);
Log.v("test", file+" "+files+" <-if m=sm getting sql data/if");
}
cursor.moveToNext();
}
cursor.close();
helper.close();
日志猫:
Alllllll null <-if m=sm getting sql data not/if
Alllllll null <-if m=sm getting sql data not/if
Alllllll null <-if m=sm getting sql data not/if
Alllllll null <-if m=sm getting sql data not/if
Alllllll Alllllll <-if m=sm getting sql data not/if
Alllllll Alllllll <-if m=sm getting sql data not/if
Alllllll Alllllll <-if m=sm getting sql data not/if
将 == 替换为 .equals() 后的错误日志:
03-28 14:31:03.985: E/SpannableStringBuilder(25898): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-28 14:31:03.985: E/SpannableStringBuilder(25898): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-28 14:31:15.030: D/AbsListView(25898): Get MotionRecognitionManager
03-28 14:31:15.085: W/ResourceType(25898): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)
03-28 14:31:15.090: W/ResourceType(25898): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)
03-28 14:31:15.225: E/SpannableStringBuilder(25898): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-28 14:31:15.225: E/SpannableStringBuilder(25898): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-28 14:31:28.950: D/AbsListView(26523): Get MotionRecognitionManager
03-28 14:31:29.060: D/libEGL(26523): loaded /system/lib/egl/libEGL_mali.so
03-28 14:31:29.075: D/libEGL(26523): loaded /system/lib/egl/libGLESv1_CM_mali.so
03-28 14:31:29.080: D/libEGL(26523): loaded /system/lib/egl/libGLESv2_mali.so
03-28 14:31:29.090: D/(26523): Device driver API match
03-28 14:31:29.090: D/(26523): Device driver API version: 10
03-28 14:31:29.090: D/(26523): User space API version: 10
03-28 14:31:29.090: D/(26523): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
03-28 14:31:29.115: D/OpenGLRenderer(26523): Enabling debug mode 0
03-28 14:31:29.135: W/ResourceType(26523): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)
03-28 14:31:29.145: W/ResourceType(26523): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)
03-28 14:31:30.780: D/AbsListView(26523): Get MotionRecognitionManager
03-28 14:31:30.800: V/test(26523): Alllllll null <-if m=sm getting sql data /not if
03-28 14:31:30.805: D/AndroidRuntime(26523): Shutting down VM
03-28 14:31:30.805: W/dalvikvm(26523): threadid=1: thread exiting with uncaught exception (group=0x4189f2a0)
03-28 14:31:30.810: E/AndroidRuntime(26523): FATAL EXCEPTION: main
03-28 14:31:30.810: E/AndroidRuntime(26523): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cn/com.example.cn.ListView2}: java.lang.NullPointerException
03-28 14:31:30.810: E/AndroidRuntime(26523): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
03-28 14:31:30.810: E/AndroidRuntime(26523): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
03-28 14:31:30.810: E/AndroidRuntime(26523): at android.app.ActivityThread.access$700(ActivityThread.java:140)
结尾