我正在使用java.But的webservice当我在服务器上部署项目时,响应没有返回。但是在我的android应用程序中得到空指针异常如何处理这种情况请告诉我。
protected void onPostExecute(String result) {
super.onPostExecute(result);
JSONArray jArr;
ArrayList<String> firstNameList=new ArrayList<String>();
ArrayList<String> lastNameList=new ArrayList<String>();
ArrayList<String> images=new ArrayList<String>();
ArrayList<String> primayEmailList= new ArrayList<String>();
try {
if(result != null){
jArr = new JSONArray(result);
rowItems = new ArrayList<RowItem>();
if(jArr.length()>0){
for (int count = 0; count < jArr.length(); count++) {
JSONObject obj = jArr.getJSONObject(count);
firstNameList.add(obj.optString("firstName"));
lastNameList.add(obj.optString("lastName"));
if(obj.optString("imageurl").contains("profilesmall.png"))
images.add(null);
else
images.add(obj.optString("imageurl"));
primayEmailList.add(obj.optString("emailid"));
}
}
}
if(firstNameList.size() == 0 && lastNameList.size() == 0) {
firstNameList.add("No");
lastNameList.add("Results");
primayEmailList.add("test@mail.com");
images.add("");
}
for (int i = 0; i < firstNameList.size(); i++) {
RowItem item = new RowItem(images.get(i),firstNameList.get(i),lastNameList.get(i),primayEmailList.get(i));
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(BdaylistActivity.this, R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(BdaylistActivity.this);
m_ProgressDialog.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
您可以检查结果字符串返回数据
if(result!= null && !result.isEmpty())
然后你可以做这个json解析。
由于
答案 1 :(得分:0)
如果我完全理解了您的问题,并且您是否想查看状态代码,请查看:
int statusCode = response.getStatusLine().getStatusCode();
// check whether its 200 or 400 or other