0

i want to store the calory values from the database inside an array called x , to do this i have to implement it inside the loop that retrain data from database ; However , when i do so , the program crash which implements an error. could any one tells me where is the problem and how can be fixed ?!

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
                    Log.d("All Products: ", json.toString());
                    products = json.getJSONArray(TAG_PRODUCT);



                    // looping through All Products
                    for (int i = 0; i < products.length(); i++) {
                        JSONObject c = products.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_PID); // also name
                        String category = c.getString(TAG_CATEGORY );
                        Double calory = c.getDouble(TAG_CALORY);

                        Log.d("After X Declaration ", calory.toString());

                        // NO NEED FOR THEM !!
                        /*
                        String unit = c.getString(TAG_UNIT );
                        String category = c.getString(TAG_CATEGORY );
                        String calory = c.getString(TAG_CALORY );
                        String carbohydrate = c.getString(TAG_CARBOHYDRATE ); */


                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();
                        x[i]=calory;
                       // Log.d("X items ", x.toString());
                        // adding each child node to HashMap key => value
                        map.put(TAG_PID, id);
                        map.put(TAG_CATEGORY, category);
                        //map.put(TAG_NAME, name);

                        // adding HashList to ArrayList
                        productsList.add(map);
                        Log.d("After X Declaration ", json.toString());
                    }
                } else {
                    // no products found
                    // Launch Add New product Activity
                    Intent i = new Intent(getApplicationContext(),
                            NewProductActivity.class);
                    // Closing all previous activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }
  • 1
    Could you post the error – G_S Mar 30 '13 at 09:46
  • E/WindowManager(2059): Activity com.example.androidhive.AllProductsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40ce91f8 V.E..... R.....ID 0,0-430,175} that was originally added here – Bashayer Abdullah Mar 30 '13 at 10:18
  • Look here: [Activity has leaked window that was originally added](http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added) – Sam R. Mar 30 '13 at 11:18

0 Answers0