I want to decode an image from webservice which is in base64 to the bitmap 
and use it in my android app. This is my method:

public Bitmap getCaptcha() throws IOException
    { 

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String json = jsonParser.getCaptcha(captchaURL, params);
        Log.i("", json);

         byte [] encodeByte=Base64.decode(json.getBytes(),Base64.DEFAULT);
         Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, 
encodeByte.length);
         return bitmap;

    }

If I decode the string which I get from getCaptcha method with my php 
script - it displays correctly. But when I do this in my application, I get 
an

 FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.assignmentexpert/com.assignmentexpert.RegisterActivity}: 
java.lang.IllegalArgumentException: bad base-64
    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
   at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.IllegalArgumentException: bad base-64
    at android.util.Base64.decode(Base64.java:161)
    at android.util.Base64.decode(Base64.java:136)
    at com.library.UserFunctions.getCaptcha(UserFunctions.java:97)
    at com.assignmentexpert.RegisterActivity.onCreate(RegisterActivity.java:66)
   at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    ... 11 more

What's is reason of it?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to