Question

My problem is the next ...

Im trying to display a image, that is defined in my phpmyadmin, and hosted in the correspondient folder, but the bitmapfactory returns nothin.

MY JAVA:

if (success == 1) {
                            // successfully received product details
                            JSONArray productObj = json.getJSONArray(TAG_PRODUCT); // JSON Array

                        // get first product object from JSON Array
                        JSONObject product = productObj.getJSONObject(0);


                        // product with this pid found
                        // Edit Text
                        txtName = (EditText) findViewById(R.id.inputName);
                        txtPrice = (EditText) findViewById(R.id.inputPrice);
                        txtDesc = (EditText) findViewById(R.id.inputDesc);


                        // display product data in EditText
                        txtName.setText(product.getString(TAG_NAME));
                        txtPrice.setText(product.getString(TAG_PRICE));
                        txtDesc.setText(product.getString(TAG_DESCRIPTION));

                        //imageview
                        imageView1 = (ImageView)findViewById(R.id.imageView1);
                        imagen_url=product.getString("TAG_IMAGEN");
                        String imagen_url2=product.optString("TAG_IMAGEN");
                        byte[] encodeByte = Base64.decode(imagen_url, Base64.DEFAULT);
                        Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);


                            imageView1.setImageBitmap(bitmap);

AND THE PHP

        $product["imagen"] = base64_encode($result["imagen"]);

It returns a error:

04-10 04:12:32.344: W/System.err(1424): org.json.JSONException: No value for TAG_IMAGEN
04-10 04:12:32.364: W/System.err(1424):     at org.json.JSONObject.get(JSONObject.java:355)
04-10 04:12:32.364: W/System.err(1424):     at org.json.JSONObject.getString(JSONObject.java:515)
04-10 04:12:32.374: W/System.err(1424):     at com.example.androidhive.EditProductActivity$GetProductDetails$1.run(EditProductActivity.java:180)
04-10 04:12:32.374: W/System.err(1424):     at android.os.Handler.handleCallback(Handler.java:733)
04-10 04:12:32.374: W/System.err(1424):     at android.os.Handler.dispatchMessage(Handler.java:95)
04-10 04:12:32.404: W/System.err(1424):     at android.os.Looper.loop(Looper.java:136)
04-10 04:12:32.404: W/System.err(1424):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-10 04:12:32.404: W/System.err(1424):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 04:12:32.414: W/System.err(1424):     at java.lang.reflect.Method.invoke(Method.java:515)
04-10 04:12:32.414: W/System.err(1424):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-10 04:12:32.414: W/System.err(1424):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-10 04:12:32.434: W/System.err(1424):     at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

The problem was the TAG, if I put :

imagen_url=product.getString("imagen");

works, but with not :

imagen_url=product.getString("TAG_IMAGEN");

I dont know why, but with this change, it works fine!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top