Android 数组或sqlite查询错误
谁能告诉我我的代码有什么问题吗 它说的是这样的错误Android 数组或sqlite查询错误,android,arrays,sqlite,arraylist,Android,Arrays,Sqlite,Arraylist,谁能告诉我我的代码有什么问题吗 它说的是这样的错误 E/AndroidRuntime(1636): at com.example.KUHP_KUHAP_KUHperdata.PencPasalUndangKUHP.onTextChanged(PencPasalUndangKUHP.java:76) E/AndroidRuntime(1636): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 这是我的代码
E/AndroidRuntime(1636): at com.example.KUHP_KUHAP_KUHperdata.PencPasalUndangKUHP.onTextChanged(PencPasalUndangKUHP.java:76)
E/AndroidRuntime(1636): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
这是我的代码哪里出错了
主类
public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3)
{
String textform = s.toString();
ArrayList<String> querybbrpa = new ArrayList<String>();
for (int position=0; position<listKamus.size(); position++)
{
String isidatabase = listKamus.get(position).toString();
int posisiarray = position;
KMP.main(textform, isidatabase, posisiarray);
querybbrpa.set(position, KMP.value);
}
String query = TextUtils.join(" AND ", querybbrpa.toArray());
listKamus = dbHelper.getAllPasalKUHPKnutmorris(query);
adapter = new ArrayAdapter<Data>(this,
android.R.layout.simple_expandable_list_item_1, listKamus);
lv.setAdapter(adapter);
}
public void onTextChanged(字符序列s、int arg1、int arg2、int arg3)
{
字符串textform=s.toString();
ArrayList querybbrpa=新的ArrayList();
对于(int位置=0;位置=1)
{
cursor.moveToFirst();
做
{
数据=新数据();
data.setArti(cursor.getString(cursor
.getColumnIndexOrThrow(COL_ISI));
data.setIstilah(cursor.getString(cursor
.getColumnIndexOrThrow(colu PASAL));
添加(数据);
}while(cursor.moveToNext());
}
返回利斯卡莫斯;
}
国民党
公共类KMP{
/**失效阵列**/
私有int[]故障;
公共静态字符串值;
/**建造师**/
公共KMP(字符串文本、字符串pat、整数pai)
{
/**为模式预构造故障数组**/
失败=新整数[pat.length()];
失败(pat);
/**找到匹配项**/
int pos=posMatch(文本,pat);
int-pindex;
pindex=pai+1;
如果(位置==-1)
KMP.value=“\u id==”;
其他的
KMP.value=“_id==”+pindex+”;
}
/**模式的失效函数**/
私有无效失败(字符串pat)
{
int n=拍片长度();
失败[0]=-1;
对于(int j=1;j=0)
i=失败[i];
如果(专利特征(j)=专利特征(i+1))
失效[j]=i+1;
其他的
故障[j]=-1;
}
}
/**函数查找模式的匹配项**/
私有int posMatch(字符串文本、字符串pat)
{
int i=0,j=0;
int lens=text.length();
int lenp=pat.length();
而(i
对不起,我的解释太简短了。我对android还是新手。我想在ContextChange中使用knutmorris搜索数据库数据,因此,当我们在edittext中键入内容/在edittext中键入text change时,下面的列表将使用knutmorris进行更改。指示第76行@Pencpasalundagkuhpit's
querybbrpa.set
。第76行在这里是“querybbrpa.set(position,KMP.value);”changequerybbrpa.set(position,KMP.value)代码>到querybbrpa.add(KMP.value)是的,错误消失了,thnx。但是,它仍然不起作用。当我在编辑文本中键入内容时,它没有显示任何结果,要么显示全部,要么根本不显示任何内容。
public List<Data> getAllPasalKUHPKnutmorris(String query)
{
List<Data> lisKamus = new ArrayList<Data>();
Cursor cursor = db.query(TB_KUHP, new String[] { COL_ID, COL_ID,
COL_ISI, COL_PASAL }, query, null, null, null, COL_PASAL);
if (cursor.getCount() >= 1)
{
cursor.moveToFirst();
do
{
Data data = new Data();
data.setArti(cursor.getString(cursor
.getColumnIndexOrThrow(COL_ISI)));
data.setIstilah(cursor.getString(cursor
.getColumnIndexOrThrow(COL_PASAL)));
lisKamus.add(data);
} while (cursor.moveToNext());
}
return lisKamus;
}
public class KMP {
/** Failure array **/
private int[] failure;
public static String value;
/** Constructor **/
public KMP(String text, String pat, int pai)
{
/** pre construct failure array for a pattern **/
failure = new int[pat.length()];
fail(pat);
/** find match **/
int pos = posMatch(text, pat);
int pindex;
pindex = pai + 1;
if (pos == -1)
KMP.value = "_id == ''";
else
KMP.value = "_id == '" + pindex + "'";
}
/** Failure function for a pattern **/
private void fail(String pat)
{
int n = pat.length();
failure[0] = -1;
for (int j = 1; j < n; j++)
{
int i = failure[j - 1];
while ((pat.charAt(j) != pat.charAt(i + 1)) && i >= 0)
i = failure[i];
if (pat.charAt(j) == pat.charAt(i + 1))
failure[j] = i + 1;
else
failure[j] = -1;
}
}
/** Function to find match for a pattern **/
private int posMatch(String text, String pat)
{
int i = 0, j = 0;
int lens = text.length();
int lenp = pat.length();
while (i < lens && j < lenp)
{
if (text.charAt(i) == pat.charAt(j))
{
i++;
j++;
}
else if (j == 0)
i++;
else
j = failure[j - 1] + 1;
}
return ((j == lenp) ? (i - lenp) : -1);
}
/** Main Function **/
public static void main(String textform, String isidatabase, int posisiarray)
{
System.out.println("Knuth Morris Pratt Test\n");
System.out.println("\nEnter Text\n");
String text = textform;
int pai = posisiarray;
System.out.println("\nEnter Pattern\n");
String pattern = isidatabase;
KMP kmp = new KMP(text, pattern, pai);
}
}