0
我正在使用遊標從數據庫中獲取基於食物名稱(paramString1)和食物組(paramString 2)的數據。食物名稱來自用戶輸入。本地變量可能尚未初始化爲遊標android
但是發現了很少的錯誤。
The local variable localCursor may not have been initialized.
在while(true)循環之後,每個localCursor都會發生此錯誤。在最後2行中的arrayofString [i]也會發生同樣的錯誤。
我爲尋找食物的方法
public Cursor searchFoods(String paramString1, String paramString2)
{
Cursor localCursor;
String str1 = paramString1.replace("'", "").replace("/", "").replace("\\", "").replace("%", "").replace(">", "").replace("<", "").replace(";", "").replace(":", "").replace("?", "");
String str2 = "";
String[] arrayOfString2;
int i1;
int i3;
int i;
int j;
String[] arrayOfString1;
if (str1.contains(" "))
{
arrayOfString2 = str1.split(" ");
i1 = 0;
int i2 = arrayOfString2.length;
i3 = 0;
if (i3 >= i2)
{
if (paramString2.length() > 0)
str2 = str2 + " AND FdGrp_Cd='" + paramString2 + "' ";
localCursor = db.rawQuery("SELECT _id, FdGrp_Cd, Long_Desc, NDB_No FROM FOOD_DES WHERE " + str2 + " ORDER BY FdGrp_Cd='0900' DESC, FdGrp_Cd='1100' DESC, FdGrp_Cd='0500' DESC, FdGrp_Cd='0100' DESC, FdGrp_Cd='1500' DESC, FdGrp_Cd='1300' DESC, FdGrp_Cd='1700' DESC, Long_Desc ASC LIMIT 300;", null);
i = 0;
j = localCursor.getColumnIndex("Long_Desc");
arrayOfString1 = new String[localCursor.getCount()];
localCursor.moveToFirst();
}
}
while (true)
{
if (localCursor.isAfterLast())
{
return localCursor;
String str4 = arrayOfString2[i3];
if (str4.length() > 1)
{
String str5 = str4.substring(-1 + str4.length(), str4.length());
if ((str5.toLowerCase().equals(str5)) && (str5.toLowerCase().equals("s")))
str4 = str4.substring(0, -1 + str4.length());
}
if (i1 + 1 < arrayOfString2.length);
for (str2 = str2 + " Long_Desc LIKE '%" + str4 + "%' AND "; ; str2 = str2 + " Long_Desc LIKE '%" + str4 + "%' ")
{
i1++;
i3++;
}
if (str1.length() > 1)
{
int k = -1 + str1.length();
int m = str1.length();
String str3 = str1.substring(k, m);
if ((str3.toLowerCase().equals(str3)) && (str3.toLowerCase().equals("s")))
{
int n = -1 + str1.length();
str1 = str1.substring(0, n);
}
}
str2 = " Long_Desc LIKE '%" + str1 + "%'";
}
arrayOfString1[i] = localCursor.getString(j);
i++;
localCursor.moveToNext();
}
}
代碼感謝您的關注。
但在方法的開始,我可以使用localCursor沒有任何錯誤。那麼,我需要在while(true)循環中聲明localCursor嗎? – czh