我不知道爲什麼下面的代碼即使在它爲TRUE的時候也總是重做錯誤。我要比較的是用戶在字符串變量'classNameGlobal'中輸入的文本的結果,以及來自DB查詢的第二個結果,該結果是來自表列的字符串值。每當我運行控制開關到其他條件不運行,如果部分 - 。 -Android如果其他條件錯誤
請看看。
String result[];
result = new String[cursor.getCount() - 1];
int i = 0;
while (cursor.moveToNext()) {
result[i] = cursor.getString(cursor.getColumnIndex("name"));
i++;
}
classNameGlobal = className.getText().toString().toUpperCase().trim();
注意:如果上面的代碼是用onclick方法寫的,除了那個結果數組聲明之外。另外,Im使用相同的方法將字符串存儲在數據庫中,即將其轉換爲大寫字母,然後對任何額外的空白區域進行triminng處理!即使當從用戶輸入的字符串的查詢和達到轉儲結果。兩者都是相同的。現在爲什麼你我總是保持得到這個else部分運行,但不是如部分-.-使用比較來自數據庫查詢和用戶輸入的字符串結果的方法IM是:
for (int b = 0; b < result.length; b++) {
if (classNameGlobal == result[b]) {
Log.d(TAG, "Inside if condition now : " + result[b] + " \t" + classNameGlobal);
db.execSQL("drop table if exists " + classNameGlobal);
/* Deleting Code File */
this.deleteFile(classNameGlobal + ".txt");
Toast.makeText(
this,
classNameGlobal + " Database Dropped Successfully ",
Toast.LENGTH_SHORT).show();
break;
} else {
Toast.makeText(
this,
"No Such Database Exists",
Toast.LENGTH_SHORT).show();
}
}