Yuvaan Chauhan Yuvaan Chauhan - 1 year ago 60
Android Question

How to Toast "No Data Found" From JSON parsing if getting null value in Android

I am parsing JSON value from URL if i get

value so i want
"data not found"

my code here

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++) {

return result;
catch(Throwable t) {
return null;
return result;

Answer Source

Add the code after doInbackground code:

protected void onPostExecute(String result) {
     if(result == null){
     Toast.makeText(getApplicationContext(),"No data found", Toast.LENGTH_LONG).show();