0

so , i'm using volley lib in my app to retrieve some data from MySQl DB, but i got a NullPointerException Error , my log files shows me that this error message came from OnErrorResponse override method,

here is my class :

public class Dress extends AppCompatActivity {

    GridView gridView;

    private static final String TAG = Downloder1.class.getSimpleName();
    Context c;
    GridView gv;
    ArrayList<ProductObjects> product = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dress);

        Intent i = this.getIntent();
        String sid = i.getExtras().getString("sid");

        Products(sid);

        gridView = (GridView) findViewById(R.id.gv);

    }
    private void Products(final String SID) {
        // Tag used to cancel the request
        String tag_string_req = "req";


        StringRequest strReq = new StringRequest(Request.Method.POST,
                AppConfig.urlAddress, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Response: " + response.toString());

                try {
                    JSONObject jObj = new JSONObject(response);
                    String Error = jObj.getString("error");


                    if (Error.equals("FALSE")){

                        int product_id = jObj.getInt("Product_ID");
                        int store_id = jObj.getInt("Store_ID");
                        int Cat_id = jObj.getInt("Category_ID");
                        int price = jObj.getInt("Price");
                        int Quentity = jObj.getInt("Quantity");
                        String product_name = jObj.getString("Product_Name");
                        String size = jObj.getString("Size");
                        String product_image = jObj.getString("PIC");
                        String product_dec = jObj.getString("Description");

                        ProductObjects products = new ProductObjects(product_id, store_id, Cat_id, price, Quentity,
                                product_name, size, product_image, product_dec);

                        products.setProduct_id(product_id);
                        products.setCat_id(Cat_id);
                        products.setStore_id(store_id);
                        products.setPrice(price);
                        products.setQuentity(Quentity);
                        products.setProduct_name(product_name);
                        products.setSize(size);
                        products.setProduct_dec(product_dec);
                        products.setProduct_image(product_image);

                        product.add(products);

                        CustomAdapter adapter = new CustomAdapter (c,product);
                        gv.setAdapter(adapter);

                    }

                    else {
                        String errorMsg = jObj.getString("msg");
                        Toast.makeText(getApplicationContext(),
                                errorMsg, Toast.LENGTH_LONG).show();
                    }
                }
                catch (JSONException e) {
                    // JSON error
                    e.printStackTrace();
                    // Error in login. Get the error message
                    Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_LONG).show();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                // Posting parameters to login url
                Map<String, String> params = new HashMap<String, String>();
                params.put("sid", SID);
                return params;
            }
        };

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
    }

}

Log File :

LogCat

Any help?

Sufian
  • 6,405
  • 16
  • 66
  • 120
tasneem
  • 1
  • 1

0 Answers0