当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Android: Second Private class is not used locally

问题描述:

I am making an android class with two methods one is to display a database contents into a listview one is to simply display a database entry onto a text view. The second one does not work

Code snippet

private String url = "http://10.0.3.2/sunshine-ems/leavelist.php";

private String url2 = "http://10.0.3.2/sunshine-ems/leavebal.php";

First

private class DownloadJSON extends AsyncTask<String, String, String> {

@Override

protected void onPreExecute() {

super.onPreExecute();

mProgressDialog = new ProgressDialog(Leavelist.this);

mProgressDialog.setTitle("Loading Services");

mProgressDialog.setMessage("Loading...");

mProgressDialog.setIndeterminate(false);

mProgressDialog.show();

}

@Override

protected String doInBackground(String... params) {

username = session.getUsername();

List<NameValuePair> params1 = new ArrayList<NameValuePair>();

params1.add(new BasicNameValuePair("username", username));

JSONObject json = jsonParser.makeHttpRequest(url, "POST", params1);

// Check your log cat for JSON reponse

Log.d("Check JSON ", json.toString());

// Create the array

arraylist = new ArrayList<HashMap<String, String>>();

try {

// Locate the array name

jsonarray = json.getJSONArray("leavelist");

for (int i = 0; i < jsonarray.length(); i++) {

HashMap<String, String> map = new HashMap<String, String>();

json = jsonarray.getJSONObject(i);

String l_id = json.getString(LEAVE_ID);

String l_type = json.getString(LEAVE_TYPE);

String l_stat = json.getString(LEAVE_STAT);

// Retrive JSON Objects

map.put(LEAVE_STAT, l_stat);

map.put(LEAVE_TYPE, l_type);

map.put(LEAVE_ID, l_id);

// 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(String file_url) {

mProgressDialog.dismiss();

// updating UI from Background Thread

runOnUiThread(new Runnable() {

public void run() {

/**

* Updating parsed JSON data into ListView

* */

ListAdapter adapter = new SimpleAdapter(

Leavelist.this,

arraylist,

R.layout.listview_services,

new String[] { LEAVE_ID, LEAVE_TYPE, LEAVE_STAT },

new int[] { R.id.transac_id, R.id.txt_service,

R.id.txt_date });

// updating listview

setListAdapter(adapter);

}

});

}

}

This is the one that doesn't work it says "Downloadstylist is not used locally"

private class DownloadStylist extends AsyncTask<String, String, JSONObject> {

private ProgressDialog progressDialog = new ProgressDialog(

Leavelist.this);

protected void onPreExecute() {

progressDialog.setMessage("Loading profile ...");

progressDialog.setIndeterminate(false);

progressDialog.setCancelable(false);

progressDialog.show();

}

protected JSONObject doInBackground(String... args) {

username = session.getUsername();

List<NameValuePair> params1 = new ArrayList<NameValuePair>();

params1.add(new BasicNameValuePair("username", username));

JSONObject json = jsonParser.makeHttpRequest(url2, "POST", params1);

// Check your log cat for JSON reponse

Log.d("Profile JSON: ", json.toString());

try {

// profile json object

jsonarray = json.getJSONArray("user");

user = new String[jsonarray.length()];

for (int m = 0; m < jsonarray.length(); m++) {

json = jsonarray.getJSONObject(m);

// Retrive JSON Objects

user[m] = json.getString("user");

}

} catch (JSONException e) {

e.printStackTrace();

}

return json;

}

@Override

protected void onPostExecute(JSONObject json) {

super.onPostExecute(json);

// dismiss the dialog after getting all products

progressDialog.dismiss();

try {

String sick_leave = json.getString("sick_leave");

// displaying all data in textview

leavebal.setText(sick_leave);

} catch (Exception e) {

e.printStackTrace();

}

}

}

网友答案:

you have declared the class, but never instantiate and call it, and since its private you will get that warning.

分享给朋友:
您可能感兴趣的文章:
随机阅读: