谁能告诉我,这里有什么问题?我一直在尝试一整天。我是 android 新手,我也不擅长阅读 logcat,因此,我真的希望有人能帮助我。应用力一直关闭。
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> eventsList;
// url to get all products list
private static String url_all_products = "http://xx.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_CUSTOMER = "customer";
private static final String TAG_PID = "pid";
private static final String TAG_FIRSTNAME = "firstname";
private static final String TAG_LASTNAME = "lastname";
private static final String TAG_ADDRESS = "address";
private static final String TAG_TOTALCOST = "totalCost";
// products JSONArray
JSONArray events = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_transaction);
// Hashmap for ListView
eventsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CustomerTransaction.this);
pDialog.setMessage("Loading. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
events = json.getJSONArray(TAG_CUSTOMER);
// looping through All Products
for (int i = 0; i < events.length(); i++) {
JSONObject c = events.getJSONObject(i);
// Storing each json item in variable
String pid = c.getString(TAG_PID);
String firstname = c.getString(TAG_FIRSTNAME);
String lastname = "Time :" +c.getString(TAG_LASTNAME);
String address = "Date :" +c.getString(TAG_ADDRESS);
String totalCost = "Venue :" +c.getString(TAG_TOTALCOST);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, pid);
map.put(TAG_FIRSTNAME, firstname);
map.put(TAG_LASTNAME, lastname);
map.put(TAG_ADDRESS, address);
map.put(TAG_TOTALCOST, totalCost);
// adding HashList to ArrayList
eventsList.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
CustomerTransaction.this, eventsList,
R.layout.list_item4, new String[] { TAG_PID,TAG_FIRSTNAME, TAG_LASTNAME, TAG_ADDRESS, TAG_TOTALCOST},
new int[] { R.id.pid, R.id.firstname, R.id.lastname, R.id.address, R.id.totalCost });
// updating listview
setListAdapter(adapter);
}
});
}
}
日志猫:
04-16 18:34:22.706: E/WindowManager(1019): Activity com.spyraa.bookstore.CustomerTransaction has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d2c1e8 V.E..... R.....ID 0,0-304,96} that was originally added here
04-16 18:34:22.706: E/WindowManager(1019): android.view.WindowLeaked: Activity com.spyraa.bookstore.CustomerTransaction has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d2c1e8 V.E..... R.....ID 0,0-304,96} that was originally added here
04-16 18:34:22.706: E/WindowManager(1019): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
04-16 18:34:22.706: E/WindowManager(1019): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
04-16 18:34:22.706: E/WindowManager(1019): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.Dialog.show(Dialog.java:281)
04-16 18:34:22.706: E/WindowManager(1019): at com.spyraa.bookstore.CustomerTransaction$LoadAllProducts.onPreExecute(CustomerTransaction.java:84)
04-16 18:34:22.706: E/WindowManager(1019): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
04-16 18:34:22.706: E/WindowManager(1019): at android.os.AsyncTask.execute(AsyncTask.java:534)
04-16 18:34:22.706: E/WindowManager(1019): at com.spyraa.bookstore.CustomerTransaction.onCreate(CustomerTransaction.java:61)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.Activity.performCreate(Activity.java:5104)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-16 18:34:22.706: E/WindowManager(1019): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 18:34:22.706: E/WindowManager(1019): at android.os.Looper.loop(Looper.java:137)
04-16 18:34:22.706: E/WindowManager(1019): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-16 18:34:22.706: E/WindowManager(1019): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 18:34:22.706: E/WindowManager(1019): at java.lang.reflect.Method.invoke(Method.java:511)
04-16 18:34:22.706: E/WindowManager(1019): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-16 18:34:22.706: E/WindowManager(1019): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-16 18:34:22.706: E/WindowManager(1019): at dalvik.system.NativeStart.main(Native Method)
太感谢了。