我有一个黑莓应用程序,它基本上对我输入的信息进行选择查询,所以如果我输入“5”,它会执行一个select * from table where id=5
,所以我会得到结果。但是,该子句的 else 语句应该返回“未找到结果”。代码贴在下面:
public void onResponse(String data, int code) {
final Vector vehicleInfo = jasonParser.parseVechicleResponse(data);
if(vehicleInfo.size() > 0 ){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
removeLoader();
UiApplication.getUiApplication().pushScreen(new VehicleSearchResultScreen(etfVehicleInfo.getText(),vehicleInfo));
}
});
}else{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
removeLoader();
Dialog.alert("No Results found.");
}
});
}
}
这段代码的问题是如果vehicleinfo.size() = 0
这个 else 语句没有运行。运行的代码是下面发布的代码,这是我的错误代码。发生收集错误时应该调用它。所以基本上,当找不到记录时,它会显示连接错误的字符串,我根本不知道为什么这个 else 语句没有运行;或者它是否运行,并且被以下语句过度运行?
public void onError(final String data, int code) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
removeLoader();
Dialog.alert("No Results Found!");
}
});
}
解析代码
public Vector parseVehicleResponse(String response){
Vector vector = new Vector();
try{
JSONObject jsonVehicleObject = new JSONObject(response);
VehicleObject vehicle = new VehicleObject();
vehicle.setChassisNum(jsonVehicleObject.getString("chassis_no"));//chassis_num
vehicle.setEngineNum(jsonVehicleObject.getString("engine_no"));//engine_num
vector.addElement(vehicle);
}catch(Exception e){
System.out.println("JSONResponseParser.parseNewsHeadlines() " + e );
}
return vector;
}
}
json
// Return encoded with JSON
$result = array(
"chassis_no"=>$chassis_no,
"engine_no"=>$engine_no,
);