my code are as following ;
private class DownloadJSON extends AsyncTask<void,> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(MainActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Android JSON Parse Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<hashmap><string,>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://192.168.0.77:8083/MyService.svc/ForAllProduct");
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray(null);
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<string,> map = new HashMap<string,>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("Code", jsonobject.getString("Code"));
map.put("Name", jsonobject.getString("Name"));
map.put("Size", jsonobject.getString("Size"));
map.put("Color", jsonobject.getString("Color"));
map.put("Category",jsonobject.getString("Category"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(MainActivity.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
========================
but error occur at doInBackground() and not connect to my web service api.