本文介绍了我正在尝试运行使用其他服务的Android应用程序,但我最终错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码用于获取下一个要输入的数据的数量。当我在浏览器中运行其余服务时,我得到结果{FetchSecondaryNumberResult:[{Res:2}]}。当我运行应用程序时,获取toast消息说发生意外错误![最常见的错误:设备可能未连接到Internet或远程服务器未启动并运行]。我连接到网络,我使用async-http 1.4.4.jar这个程序。
请帮我解决这个问题。
the below code is used to get the number of datas to be entered next. when i run the rest service in browser i get result {"FetchSecondaryNumberResult":[{"Res":2}]}. when i run the app the get the toast message saying "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]". i am connected to the net and i use async-http-1.4.4.jar for this app.
please help me to solve this.
AsyncHttpClient fetchSecond=new AsyncHttpClient();
fetchSecond.put("http://pharmamax.solutionsmax.com/PackageMax.svc/FetchSecondaryNumber", params,new AsyncHttpResponseHandler()
{
@Override
public void onSuccess(String response)
{
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
try{
JSONObject obj3 = new JSONObject(response);
JSONArray jsonArray3 = obj3.getJSONArray("FetchSecondaryNumberResult");
int length = jsonArray3.length();
if(length!=0)
{
for(int i=0;i<length;i++)
{
JSONObject user = jsonArray3.getJSONObject(i);
//result=user3.getString("Res").toString();
number.setText(user.get("Res").toString());
}
}
else
{
Toast.makeText(getApplicationContext(), "no data", Toast.LENGTH_LONG).show();
}
}catch(JSONException e){
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
//e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Throwable error,String content){
//Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show();
if(statusCode == 404){
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
else if(statusCode == 500){
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
}
}
});
推荐答案
这篇关于我正在尝试运行使用其他服务的Android应用程序,但我最终错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!