-1

您好我正在尝试为我的应用程序创建一个 sqlite 查询,我需要读取一个 txt 字符串,将字符串拆分为单个单词并创建查询,这是我的代码

s= “my string with some words”;
String aWords[] = s.split(" "); 
String querysearch = “body like ‘%” + aWords[0]+ "%'";
if((aWords[1] != null) && (aWords[1].length() > 3)) {querysearch = querysearch + " or      body like  '%" + aWords[1]+ "%'";}
if((aWords[2] != null) && (aWords[2].length() > 3)) {querysearch = querysearch + " or  body like  '%" + aWords[2]+ "%'";}

应用程序在这里崩溃

if((aWords[1] != null) && (aWords[1].length() > 3)) 

我不明白为什么,它应该只检查字符串是否为空且至少有 4 个字符长

任何帮助表示感谢

4

1 回答 1

0

如果它崩溃,那么你的数组有少于两个元素。只需在aWords.length > 1您的条件中添加一个。

于 2013-11-01T16:19:27.170 回答