Click here to Skip to main content
15,916,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Java
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();
              }
			 }

			
			
		});
Posted

1 solution

well i found out how to make it work

the mistake was i used fetchsecond.put();

this must be replaced by fetchsecond.get();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900