SQLテーブルからリストビューに表示する同じモジュールを持つファイルのみを選択しようとしています。if (module == smodule) を使用している場合、アプリは問題ありませんが、if (module.equals(smodule)) を使用して if ステートメントがジャンプし、アプリがクラッシュしています。
ありがとう@Nambariの問題は、データベースのモジュールの値にnullがあったことです。
「String module = ""」のようにインスタンス化する提案をありがとう@Buhake Sindi
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)
終わり