setDist3(..)コードの後に、カーソルにデータがないと言って停止します。何が問題だろう!すべてのテーブル名とカラム名が一致します。なぜコードの途中でelse文を返すのですか?Android SQLite: "カーソルにデータがありません"エラー
public List<Information> findTwoBus(Integer fromNode, Integer toNode){
List<Information> l_info = new ArrayList<Information>();
String SQL ="SELECT '2' AS type, s1.`bid` AS busid1, s3.`bid` AS busid2, '0' AS busid3, ch1.`changeid` AS changeid1, '0' AS changeid2,(s2.`distance` - s1.`distance`) AS dist1,(s4.`distance` - s3.`distance`) AS dist2, '0' AS dist3 FROM `changestations` AS ch1, `routes` AS b1, `routes` AS b2,`routestations` AS s1 INNER JOIN `routestations` AS s2 ON s1.`bid` = s2.`bid` INNER JOIN `routestations` AS s3 ON s2.`pid` = s3.`pid` INNER JOIN `routestations` AS s4 ON s3.`bid` = s4.`bid`WHERE s1.`pid` = :from AND s2.`pid` = ch1.`changeid` AND s4.`pid` = :to AND s2.`distance` > s1.`distance` AND s4.`distance` > s3.`distance` AND b1.`id` = s1.`bid` AND b2.`id` = s3.`bid` AND b1.`similarity` <> b2.`similarity` ORDER BY (dist1 + dist2) LIMIT 5";
Cursor res = myDataBase.rawQuery(SQL,new String[]{String.valueOf(fromNode), String.valueOf(toNode)});
if(res.getCount() > 0){
res.moveToFirst();
do{
Information info = new Information();
info.setType(Integer.parseInt(res.getString(res.getColumnIndex("type"))));
info.setBusid1(Integer.parseInt(res.getString(res.getColumnIndex("busid1"))));
info.setBusid2(Integer.parseInt(res.getString(res.getColumnIndex("busid2"))));
info.setBusid3(Integer.parseInt(res.getString(res.getColumnIndex("busid3"))));
info.setChangeid1(Integer.parseInt(res.getString(res.getColumnIndex("changeid1"))));
info.setChangeid2(Integer.parseInt(res.getString(res.getColumnIndex("changeid2"))));
//code runs upto here
info.setDist3(Integer.parseInt(res.getString(res.getColumnIndex("dist3"))));
// from here it says that cursor has no data in logcat and crashes
info.setDist2(Integer.parseInt(res.getString(res.getColumnIndex("dist2"))));
info.setDist1(Integer.parseInt(res.getString(res.getColumnIndex("dist1"))));
l_info.add(info);
res.moveToNext();
} while(!res.moveToLast());
} else{
Log.e("SQL Query Error","Cursor has no data");}
return l_info;
}
5月17日17:33:16.860 8665から8665/com.example.tripathee.gantabya E/SQLクエリエラー:33:カーソルはデータ
5月17日17を持っていません16.860 8665- 8665/com.example.tripathee.gantabya W/dalvikvm:スレッドID = 1:捕捉されない例外で終了スレッド(グループ= 0x4167ec80)
その文を取得する前に、ログの猫 –