Click here to Skip to main content
15,921,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
[no name] 10-Mar-15 10:15am    
"but error occur at doInBackground()"

You should post the error message.
MgKyaing 12-Mar-15 7:00am    
url=(java.long.String@3808)"http://localhost:8083/MyService.svc/ForAllProduct"
cause="java.net.ConnectionException: fail to connect to /127.0.0.1(port 8083):connect fail
[no name] 12-Mar-15 8:02am    
Well, then there's apparently no listener running on that address+port. Check your service and the address. Try http://localhost:8083/MyService/ForAllProduct
MgKyaing 16-Mar-15 5:44am    
ys,sis....my webservice address is :http://127.0.0.1:8083/MyService.svc/ForAllProduct.
but i am not ok.sir to connect my android project to localhost webservice.

1 solution

I think the problem come from your link
http://192.168.0.77:8083/MyService.svc/ForAllProduct[^]
ForAllProduct what's is the extension of this file. Is this ForAllProduc.php or .asp

It's better if you post the error message
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900