0

I am parsing JSON value from URL if i get null value so i want Toast "data not found"
my code here

    @Override
    protected List<Details> doInBackground(String... params) {
        List<Details> result = new ArrayList<Details>();
        ServiceHandler serviceHandler=new ServiceHandler(TrainshwstnActivity.this);
            String u = new String(params[0]);
            String JsonStr=serviceHandler.makeServiceCall(u, ServiceHandler.GET);
            Log.d("Response: ", "> " + JsonStr);
               if (JsonStr != null) {
                    try {                       
                    JSONArray arr = new JSONArray(JsonStr);
                    for (int i=0; i < arr.length(); i++) {
                        result.add(convertContact(arr.getJSONObject(i)));
                    }

                    return result;
                }
                catch(Throwable t) {
                    t.printStackTrace();
                }
                return null;
            }
        return result;
        }
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63
Yuvaan Chauhan
  • 344
  • 1
  • 3
  • 12

1 Answers1

1

Add the code after doInbackground code:

protected void onPostExecute(String result) {
     if(result == null){
     Toast.makeText(getApplicationContext(),"No data found", Toast.LENGTH_LONG).show();
     }
 }
W4R10CK
  • 5,502
  • 2
  • 19
  • 30