Wondering if its way to check if the json url is null? by this I mean if url returning null and not json array/objects.
is there some way I can check it?
I have following code and I really wondering how I should do it.
class LoadAllGB extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(ListViser.this);
mProgressDialog.setMessage("Vent Venligst..");
mProgressDialog.setTitle("Henter");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
protected String doInBackground(String... args) {
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String dato = df.format(Calendar.getInstance().getTime());
DateFormat df2 = new SimpleDateFormat("HH");
String klok = df2.format(Calendar.getInstance().getTime());
String url = "http://192.168.1.15";
Log.w("leyth", "Leyth" + url);
JSONArray json = jParser.getJSONFromUrl(url);
try {
//listen tømmes
for(int i = 0; i < json.length(); i++){
JSONObject c = json.getJSONObject(i);
String time = c.getString(Tag_time);
String cover = c.getString(Tag_cover);
String artist = c.getString(Tag_artist);
String title = c.getString(Tag_title);
HashMap<String, String> map = new HashMap<String, String>();
map.put(Tag_time, time);
map.put(Tag_cover, cover);
map.put(Tag_artist, artist);
map.put(Tag_title, title);
abcList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",
Toast.LENGTH_LONG).show();
Log.e("JSON Parser fejl", "fejl da man prøve og hente data " + e.toString());
}
return null;
}
protected void onPostExecute(String file_url) {
if(file_url!=null)//Do your validation for result
{
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",
Toast.LENGTH_LONG).show();
}
if(mProgressDialog.isShowing()){
mProgressDialog.dismiss();
}
// Locate the listview in listview_main.xml
adapter = new ListViewAdapter(ListViser.this, abcList);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
registerForContextMenu(listview);
}
}