0

I am building an articles reading android application like TechChurn. I am fetching data from server in the form of json.

I am parsing title, author name and articles-content from json and displaying it in list-view.
The problem i am facing is that i need a toast when there is no response from server end means that if i request

Hitesh Matnani
  • 533
  • 2
  • 8
  • 26
  • 1
    What do you mean no response? Error? Or blank? – Niko Adrianus Yuwono Oct 03 '14 at 05:41
  • you should have responses check it properly or make your question more clear – Abhishek Chaubey Oct 03 '14 at 05:47
  • Thanks! basically some time happen is that the server also dose not have that data for example suppose if i am showing Google link in my web view and some time Google server is down that time there is no reply for any of user query search. in this condition the application toast a message. – Hitesh Matnani Oct 03 '14 at 05:53

2 Answers2

0
JSONParser jsonParser = new JSONParser();
JSONObject jsonData;

jsonData= jsonParser.getJSONFromUrl(
                        "Ur URL",
                        "Ur method like POST", Ur parammeter for the Url);

Code To check whether the response is null or not.

if(jsonData==null){
//Do something here
}
else{
//Proceed here
}
W I Z A R D
  • 1,224
  • 3
  • 17
  • 44
  • Thanks can you please tell me in this condition i am using this code - JsonArrayRequest movieReq = new JsonArrayRequest(URL, new Response.Listener() {@Override public void onResponse(JSONArray response) { Log.d(TAG, response.toString()); // Parsing jsonfor (int i = 0; i < response.length(); i++) {try { JSONObject obj = response.getJSONObject(i); Movie movie = new Movie(); movie.setTitle(obj.getString("title")); movie.setDate(obj.getString("date")); movieList.add(movie); – Hitesh Matnani Oct 03 '14 at 06:27
  • @HiteshMatnani u can do like `if(response.length() == 0){ //Do somthing } else { //Proceed }` – W I Z A R D Oct 03 '14 at 09:33
  • This will run when the url is find in the server. but i need is that when i parse the url to server to get data if that time the url also not founded by server and there is no proper respones that time a toast – Hitesh Matnani Oct 06 '14 at 05:18
  • @HiteshMatnani then wat is ur issue? – W I Z A R D Oct 06 '14 at 09:31
0

How about using a time out in your connection?

ChaturaM
  • 1,507
  • 18
  • 32