开发者

Displaying an image coming from database through web service in Android

I am trying to display an image using ImageView in Android. The image data is coming from Database through a Web Service. All other values other than image is successfully visible on android screen. I tried following code :

Bitmap bm=BitmapFactory.decodeStream((InputStream)response.getProperty(7));
image.setImageBitmap(bm);

But i am getting class cast exception as:

12-30 12:51:52.241: ERROR/AndroidRuntime(310): FATAL EXCEPTION: main
12-30 12:51:52.241: ERROR/AndroidRuntime(310): java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at com.trueVUE.modules.report.MainSimulation.onClick(MainSimulation.java:131)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.view.View.p开发者_StackOverflowerformClick(View.java:2408)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.view.View$PerformClick.run(View.java:8816)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.os.Handler.handleCallback(Handler.java:587)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.os.Looper.loop(Looper.java:123)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at java.lang.reflect.Method.invokeNative(Native Method)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at java.lang.reflect.Method.invoke(Method.java:521)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-30 12:51:52.241: ERROR/AndroidRuntime(310):     at dalvik.system.NativeStart.main(Native Method)

Please suggest me the solution for this.

Thanks & Regards, Rahul Jaiswal


easiest and simplest would be display it in a webview or use set in Image View using setImageURI


Bitmap bimage=  getBitmapFromURL(bannerpath);
image.setImageBitmap(bimage);

 public static Bitmap getBitmapFromURL(String src) {
        try {
            Log.e("src",src);
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            Log.e("Bitmap","returned");
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("Exception",e.getMessage());
            return null;
        }
    }

Add this line in your android-menifest.xml

<uses-permission android:name="android.permission.INTERNET" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜