I am calling a web service to get a object out of the json, then I need to pass that object that I have made a string to another web service. I have each web service call in a AsyncTask. I am unable to pass that first jsonObject named map to another subClass. Don't worry about the actaul calls, I want to pass the string "map" to the second AsyncTask to be able to use that in the web call. Both these classes are sub classes.
public class aisleStoreID extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... params) {
String urlExtension = "getpartnerstore?latitude=" + lat + "&longitude=" + lng + "&partner_id=" + "60" + "&vendor_store_nbr=" + id + "";
final String authToken = Utils.md5(urlExtension);
String urlString = "http://aisle411.ws/webservices2/getpartnerstore.php?latitude=" + lat + "&longitude=" + lng + "&partner_id=" + 60 + "&vendor_store_nbr=" + id + "&auth=" + authToken;
InputStream inputStream = null;
try {
HttpResponse response = ConnectionHelper.executeHttpGetStoreMap(urlString);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
result = sb.toString();
if (response != null) {
result = response.toString();
JSONObject jsonObject = new JSONObject(String.valueOf(sb));
JSONArray arr = jsonObject.getJSONArray("stores");
JSONObject jObj = arr.getJSONObject(0);
String map = jObj.getString("store_map_url");
Intent intent = new Intent(this, getStoreMap.class);
intent.putExtra("retailer_store_id", map);
startActivity(intent);
}
} catch (Exception e) {
System.out.println(e.getMessage());
return e.getMessage();
}
return result;
}
#Override
protected void onPostExecute(String result) {
System.out.println(" What's in it" + result);
}
}
public class getStoreMap extends AsyncTask<String, String, String> {
Bundle bundle = getIntent().getExtras();
String storeMap = bundle.getString("retailer_store_id");
#Override
protected String doInBackground(String... params) {
String urlExtension = "map?latitude=" + lat + "&longitude=" + lng + "&partner_id=" + "60" + "&retailer_store_id=" + map + "";
final String authToken = Utils.md5(urlExtension);
String urlString = "http://aisle411.ws/webservices2/map.php?latitude=" + lat + "&longitude=" + lng + "&partner_id=" + 60 + "&retailer_store_id=" + map + "&auth=" + authToken;*/
return null;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}
}
Try to move your code of extracting storeMap from extras to doInBackground method.
You need to do this in your aisleStoreID AsyncTask' onPostExecute():
#Override
protected void onPostExecute(String result) {
System.out.println(" What's in it" + result);
String params[]=new String[1];
params[0]=result;
new getStoreMap().execute(params);
}
and then get the params in doInBackground of getStoreMap AsyncTask.
Note: Intent is used to send extras from one to another component(like activity,services,Broadcast Receivers or Content Providers) , not between classes or subclasses.
An Async Task isn't meant to be an activity. It's meant to work in the background while you get the data for the activity. The difference is important and I would recommend reading up on it in the android docs
I would try returning map from doInBackground and then calling the other AsyncTask in the onPostExecute also you might be able to collapse some of those variables from
JSONObject jsonObject = new JSONObject(String.valueOf(sb));
JSONArray arr = jsonObject.getJSONArray("stores");
JSONObject jObj = arr.getJSONObject(0);
to this
JSONObject jsonObject = new JSONObject(String.valueOf(sb)).getJSONArray("stores").getJSONObject(0);
In onPostExecute
public class aisleStoreID extends AsyncTask<String, String, String> {
#Override
String doInBackground(String... params) {
// ...
return map;
}
#Override
protected void onPostExecute(String result) {
new getStoreMap().execute(result);
}
}
Related
I want to make my code wait until there is a change anywhere in my class to the variable finaloutcomes. Is there any way to do this? I am carrying this out within an Asynctask, which I posted below.
public HashMap<String,String> checkbetoutcome() {
new LoadAllGamet().execute();
// INSERT CODE HERE
return finaloutcomes;
}
ASYNCTASK
class LoadAllGamet extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... args) {
// HttpParams httpParameters = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(httpParameters, 250000);
//HttpConnectionParams.setSoTimeout(httpParameters, 250000);
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url_check_bet);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("param", bet));
// Log.d("CURRENTITEM", currentitem);
try {
post.setEntity(new UrlEncodedFormEntity(params));
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
HttpResponse response = client.execute(post);
Log.d("Http Post Responsecxxx:", response.toString());
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
JSONObject jObj = null;
String json = "";
client.getConnectionManager().closeExpiredConnections();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
if (!line.startsWith("<", 0)) {
if (!line.startsWith("(", 0)) {
sb.append(line + "\n");
}
}
}
is.close();
json = sb.toString();
json = json.substring(json.indexOf('{'));
// Log.d("sbsssssssssss", json);
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
allgames = jObj.getJSONArray("bets");
// Log.d("WHAT IS MY ARRAY?", allgames.toString());
for (Integer i = 0; i < allgames.length(); i++) {
HashMap<String,String> statuses = new HashMap<>();
JSONObject c = allgames.getJSONObject(i);
JSONArray currentbet = c.getJSONArray("bet");
Log.d("Single array",currentbet.toString());
// Storing each json item in variable
for (Integer a = 0; a < currentbet.length();a++) {
JSONObject d = currentbet.getJSONObject(a);
String Result = d.getString("Result");
String id = d.getString("gid");
Log.d("RESULTS",Result);
statuses.put(id, Result);
}
allbetsmap.add(i, statuses);
Log.d("ddd", statuses.toString());
Log.d("AAA", allbetsmap.get(i).toString());
}
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
}
catch (IOException e) {
e.printStackTrace();
}
return "";
}
#Override
protected void onPostExecute(String param) {
Log.d("SIZE",Integer.toString(allbetsmap.size()));
//ArrayList<Map<String,String>> allbetsmap = new ArrayList<>();
//ArrayList<Map<String,String>> passtocheck = new ArrayList<>();
if (allbetsmap.size() == passtocheck.size()) {
for (int i = 0; i < allbetsmap.size();i++) {
if (allbetsmap.get(i).size() == passtocheck.get(i).size()) {
String finaloutcome = "won";
for (String a : allbetsmap.get(i).keySet()) {
String f = allbetsmap.get(i).get(a);
if(f.equals("null")) {
finaloutcome = "open";
}
else if (! (f.equals(passtocheck.get(i).get(a)))) {
finaloutcome = "lost";
break;
}
}
finaloutcomes.put(Integer.toString(i),finaloutcome);
}
}
}
Log.d("Vital",finaloutcomes.toString());
}
}
Ok, forget what I wrote before. I didn't realize you were writing code for android. Here is an improved version of LoadAllGamet. There are two important things here. 1. define as much as possible locally i.e. inside a method or - if that's not possible - inside the class. 2. return the result instead of putting it into some variable.
class LoadAllGamet extends AsyncTask<String, Void, HashMap<String,String>> {
protected HashMap<String,String> doInBackground(String ... args) {
HashMap<String,String> finaloutcomes = new HashMap<>(),
HashMap<Integer, HashMap<String,String>> allbetsmap = new HashMap<>();
HttpClient client = new DefaultHttpClient();
...
Log.d("SIZE",Integer.toString(allbetsmap.size()));
if (allbetsmap.size() == passtocheck.size()) {
...
}
Log.d("Vital",finaloutcomes.toString());
return finaloutcomes;
}
}
Whenever you want to do something that might take some time you should not run
that in the UI thread of you App since it can block your UI.
Instead run it asynchronously. One way of doing this is to use AsyncTask.
Let's assume you want to do something and while that something is being processed
you also want to update the UI (e.g. progress bars) from time to time. And once you
are finished you want to do something else with the result.
Here is one way of writing this.
void doSomething() {
new AsyncTask<String, Progress, Result>() {
protected Result doInBackground(String... args) {
//some code
publishProgress(values);
//some more code
return result;
}
protected void onProgressUpdate(Progress ... values) {
updateProgessBars(values);
}
protected void onPostExecute(Result result) {
doSomethingElse(result);
}
}.execute();
}
The String in new AsyncTask<String, Progress, Result> is the type of the
arguments to doInBackground. Often however you don't really need that unless
you want to pass arguments into execute.
Progress is the type of the values you want to send to onProgressUpdate. That
one you only need if you want to update your UI while the background processing
is still going on.
Result is of course your result type. Whatever you want to happen after
the doInBackground is finished you write into onPostExecute.
Hello i have a class which runs my getQus class(via asynctask)
The problem right now is that im trying to set it in such a way that if
my return result is null, to rerun the getQus again with updated variables, i.e to increase my topic& lvl till i get a valid result.
This is my flow of my system.
1st class( set topic&lvl)-> Pass topic&lvl over to getQus -> getQus returns result via onPostExecute(delegate).
1st Class Code
public void GenerateQus(){
//run code to get new qus
x.setLvl(lvl);
x.setTopic(topic);
System.out.println("GENERATEQUS:"+ lvl +" , "+topic);
new getQus(CAT.this).execute(x);
}
getQus Class
protected Question doInBackground(Level... params) {
int r = params[0].getLvl();
int z = params[0].getTopic();
System.out.println("getQlvl:" + r);
System.out.println("getQtopic:" + z);
String range = String.valueOf(r);
String topic = String.valueOf(z);
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("range",range));
nameValuePairs.add(new BasicNameValuePair("topic",topic));
int q_id = 0;
String result=null;
String q_qus =" ";
String result2 = " ";
Question q = new Question();
InputStream is = null;
try {
Globals g = Globals.getInstance();
String ip = g.getip();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://"+ip+"/fyp/qus.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result2=sb.toString();
System.out.println("TEDASD: "+result2);
if(result2.equals("[]")){
//to rerun again
}
What should i do so that getQus will re-call itself again? Thanks in advance!
If I understood your problem correctly, you just want to rerun logic in doInBackground. So, why don't you just do something like this?
protected Question doInBackground(Level... params) {
Question q;
while((q = doTheStuff(params))==null){
updateParams(params);
}
return q;
}
private Question doTheStuff(Level.. params){
//your logic here
}
private void updateParams(Level.. params){
//update params here
}
If you can update x only in the main thread, you can reexecute the task in onPostExecute:
public class SomeActivity extends Activity {
private X x = new X();
#Override protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AsyncTask<X, String, Long>() {
#Override protected Long doInBackground(final X... params) {
// do something here
return null;
}
#Override protected void onPostExecute(final Long result) {
if (result == null) {
// update args and restart task
x.setFoo("a");
x.setBar("b");
execute(x);
}
}
}.execute(x);
}
private class X {
String foo;
String bar;
public void setFoo(final String foo) {
this.foo = foo;
}
public void setBar(final String bar) {
this.bar = bar;
}
}
}
In onPostExecute() method you will get the result. so if your result is null there the start the AysncTask there itselt.
The following code creates a background task and executes it.
String dateString = null;
if (dateSelected)
dateString = Utils.parseDateToMsTimestamp(selectedDate);
final String ori = originCode;
final String dest = destinationCode;
RequestScheduleTask requestScheduleTask = new RequestScheduleTask();
requestScheduleTask
.execute(ori, dest, dateString);
originCode and destinationCode are instance variables.
The following is what the background task does.
private class RequestScheduleTask extends
AsyncTask<String, Void, List<CUSchedule>> {
#Override
protected List<CUSchedule> doInBackground(String... args) {
List<CUSchedule> cuSchedules = null;
try {
cuSchedules = CURestCommunicator
.requestSUScheduleByOriginAndDestination(args[0],
args[1], args[2]);
} catch (NetworkException e) {
}
return cuSchedules;
}
#Override
protected void onPostExecute(List<CUSchedule> result) {
if (result == null) {
raiseError("Server Error");
}
InnoBusApplication innoBusApplication = (InnoBusApplication) getApplication();
innoBusApplication.setCuSchedules(result);
super.onPostExecute(result);
}
}
The following is part of what the http call does.
public static List<CUSchedule> requestSUScheduleByOriginAndDestination (
String origin, String destination, String date) throws NetworkException {
Log.d("upload", "up");
origin = Utils.shortNameForCity(origin);
destination = Utils.shortNameForCity(destination);
HttpClient client = null;
String url = "http://" + SVR + "/innobussvr/BusSchedulesSearchByOrgDestStartTimeEndTime/"
+ origin + "/" + destination;
Log.d("url", url);
...
}
The following is the URL that results.
http://192.168.0.150/innobussvr/BusSchedulesSearchByOrgDestStartTimeEndTime/null/null
I understand that this is a thread visibility problem. How can I solve it?
Simple Solution just create a Constractor for RequestScheduleTask that takes 2 String and pass them then create inside the Task class 2 local string var.
I have such JSONparser class:
public class JSONParser {
static InputStream is = null;
static JSONObject jObj;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
and such activity:
public class BankExchangersListActivity extends ExpandableListActivity {
private static String url;
// JSON Node names
private static final String TAG_Exchangers = "bank_exchangers";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_address = "address";
private static final String TAG_location_name = "location_name";
private static final String TAG_latitude = "latitude";
private static final String TAG_longitude = "longitude";
private static final String TAG_exchanger_type_name = "exchanger_type_name";
private static final String TAG_exchanger_curr_value = "value";
private static final String TAG_currency_list_name = "currency_list_name";
private static final String TAG_direction_of_exchange_name = "direction_of_exchange_name";
JSONArray banks = null;
JSONArray exc_currencies = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
String bank;
bank = this.getIntent().getStringExtra("Bank_id");
url = "****/**_**_***_list/"+bank+".json";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bank_exchangers_list);
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
ArrayList result = new ArrayList();
try {
// Getting Array of Contacts
banks = json.getJSONArray(TAG_Exchangers);
// looping through All Contacts
for(int i = 0; i < banks.length(); i++){
JSONObject c = banks.getJSONObject(i);
exc_currencies = c.getJSONArray("currency_values");
HashMap<String, String> map2 = new HashMap<String, String>();
ArrayList secList = new ArrayList();
for(int k = 0; k < exc_currencies.length(); k++){
JSONObject m = exc_currencies.getJSONObject(k);
String currency = m.getString(TAG_exchanger_curr_value);
String currency_list_name = m.getString(TAG_currency_list_name);
String direction_of_exchange_name = m.getString(TAG_direction_of_exchange_name);
Log.e("wazzzup", currency); //here is trouble: how to do new array with linking to parent?
HashMap child = new HashMap();
child.put(TAG_exchanger_curr_value, currency );
child.put(TAG_currency_list_name, currency_list_name );
child.put(TAG_direction_of_exchange_name, direction_of_exchange_name );
secList.add(child);
}
// Storing each json item in variable
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
Log.e("name", name); //here is trouble: how to do new array with linking to parent?
String address = c.getString(TAG_address);
String location_name = c.getString(TAG_location_name);
String latitude = c.getString(TAG_latitude);
String longitude = c.getString(TAG_longitude);
String exchanger_type_name = c.getString(TAG_exchanger_type_name);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_NAME, name);
map.put(TAG_address, address);
map.put(TAG_location_name, location_name);
map.put(TAG_latitude, latitude);
map.put(TAG_longitude, longitude);
map.put(TAG_exchanger_type_name, exchanger_type_name);
// adding HashList to ArrayList
contactList.add(map);
result.add(secList);
}
} catch (JSONException e) {
e.printStackTrace();
}
/*ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.bank_exchanger_list_element,
new String[] { TAG_NAME, TAG_location_name, TAG_address, TAG_exchanger_type_name, TAG_latitude, TAG_longitude }, new int[] {
R.id.bank_e_n, R.id.nas_punkt_e_n , R.id.adress_obm_e_n , R.id.tip_obm_e_n , R.id.shirota_e_n , R.id.dolgota_e_n });
setListAdapter(adapter);*/
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
contactList,
R.layout.bank_exchanger_list_element,
new String[] { TAG_NAME, TAG_location_name, TAG_address, TAG_exchanger_type_name, TAG_latitude, TAG_longitude },
new int[] {
R.id.bank_e_n, R.id.nas_punkt_e_n , R.id.adress_obm_e_n , R.id.tip_obm_e_n , R.id.shirota_e_n , R.id.dolgota_e_n },
result, //something goes here
R.layout.exchanger_currencies,
new String[] {TAG_exchanger_curr_value, TAG_currency_list_name, TAG_direction_of_exchange_name},
new int[] { R.id.currencyvalue_e_n, R.id.currency_list_name_e_n, R.id.direction_of_exchange_e_n}
);
setListAdapter( expListAdapter );
ExpandableListView elv = (ExpandableListView) getExpandableListView();
for(int i=0; i < expListAdapter.getGroupCount(); i++)
elv.expandGroup(i);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.bank_exchangers_list, menu);
return true;
}
}
On android 2.3.3 it works properly. But on 4.x i see errors, after searching I understood that I need to use AsyncTask. Is it true?
But how do I use it here? If there are any useful examples, please let me know.
Just how to get it working on Android 4.x?
You should already use AsyncTask under Android 2.x. It greatly improves responsiveness. Here is a fragment from my MEGA API library (currently under development):
private class AsyncRequestConnection extends AsyncTask<Void, Void, String> {
private final Request request;
public AsyncRequestConnection(Request request) {
this.request = request;
}
#Override
protected String doInBackground(Void... params) {
try {
HttpPost p = createRequestHttpMessage(request);
String resp = new String(stripResponse(getRequestClient().execute(p)));
Log.v(TAG, resp);
return resp;
} catch (Exception e) {
Log.e(TAG, "Cannot complete API request", e);
cancel(false);
return null;
}
}
#Override
protected void onCancelled() {
request.backoff();
if (request.hasReachedMaxBackoff()) {
request.cancel(R.string.error_internal);
} else {
requestQueue.enqueue(request);
}
requestConnection = null;
nextRequest();
}
#Override
protected void onPostExecute(String result) {
if (result != null) {
request.attachResponse(result);
request.handleResponse();
requestConnection = null;
nextRequest();
} else {
request.cancel(R.string.error_internal);
}
}
}
doInBackgroud() is the only method that is run on a different thread. Here, all your costly operations should happen.
getRequestClient() returns a HttpClient (AndroidHttpClient.newInstance(AGENT_NAME) or reused object for multiple requests in a row).
Since you are running muliple threads here, make sure doInBackground() does not access any global data structure. In my example, get getRequestClient() is sure to be only called from this location and there is only one such AsyncTask at any time. Otherwise you need some kind of mutex. Also, the Request object is sure to used by this class exlusively. Event handling (call-back methods) is implemented in the Request object as well but for simpler tasks you could simply do everything you want to do in onCancel() and onPostExecute().
If you only want to download a JSON object and parse it, you probably won't even need a constructor and private member variables. Simply replace the first Void by String to pass the URL string to doInBackground() and replace String by JSONObject.
I have an asynctask that - when executed - is cancelled right away.
My class looks like this:
public class JSONParser extends AsyncTask<String, Void, JSONArray> {
private ListFragment fragment;
#Override
protected JSONArray doInBackground(String... strings) {
JSONArray ja = null;
String string = "";
try {
URL url = new URL(strings[0]);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
string = br.readLine();
ja = new JSONArray(string);
} catch (Exception e ) {
Log.w("Special", e.toString());
}
return ja;
}
public JSONParser(ListFragment fragment) {
this.fragment = fragment;
}
#Override
protected void onPostExecute(JSONArray jsonArray) {
try {
ArrayList<HashMap<String ,String>> datalist = new ArrayList<HashMap<String, String>>();
int i = 0;
while (i < jsonArray.length()) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject tool = jsonArray.getJSONObject(i);
map.put("id", tool.getInt("Id") + "");
map.put("name", tool.getString("Name"));
datalist.add(map);
i++;
}
fragment.setListAdapter(new SimpleAdapter(fragment.getActivity(), datalist, R.layout.tools_list, new String[] {"name"}, new int[] {R.id.text}));
} catch (Exception e) {
e.getMessage();
}
}
}
and from my fragment I'm calling it like this
AsyncTask task = new JSONParser(this).execute("http://10.0.2.2:1288/webservice/gettools.aspx");
Using the debugger I can see that as soon as the constructor is called, it skips to onCancelled() and returns. The URL is valid and working, I get no messages in the Log, and the JSON is valid.
Update: Also I have the required permission and OnCancelled() is called before it enters doInBackground(). doInBackground() is never called.
Any ideas?
I'm using IntelliJ and an AVD with Android 4.0.3.
Do you have set Internet permissions in your AndroidManifest?
Are you sure that in the doInBackground there is no exception fired?
Maybe it could be a better idea to also put the while (i < jsonArray.length()) part in the doInBackground :) (for performance)
Code to read String:
BufferedReader reader = new BufferedReader(yourInputStreamReader,8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
oehm...
you are creating your task with an activity object (this) (???)
AsyncTask task = new JSONParser(this).execute("http://10.0.2.2:1288/webservic /gettools.aspx");
but your task expects a View
public JSONParser(ListFragment fragment) {
im surprised that this doesnt throw an exception