Converting Image from ImageView to Base64 String
<p>I'm trying to convert image from <code>IMAGEVIEW</code> not in my <code>Drawable</code> to Base64 String with this code below but its causing a <code>NullPointerException</code>.</p>

<p>Here is the code:</p>

<pre><code>ImageView iv1 = (ImageView)findViewById(R.id.imageView1);
iv1.buildDrawingCache();
Bitmap bmap = iv1.getDrawingCache();
ByteArrayOutputStream bos = new ByteArrayOutputStream();  
bmap.compress(CompressFormat.PNG,100,bos); 
byte[] bb = bos.toByteArray();
String image = Base64.encodeBytes(bb);
</code></pre>

<p>Here is what logcat says:</p>

<pre><code>04-30 11:38:23.233: E/AndroidRuntime(17284): FATAL EXCEPTION: main
04-30 11:38:23.233: E/AndroidRuntime(17284): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.imageurl/com.example.imageurl.MainActivity}: java.lang.NullPointerException
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.os.Looper.loop(Looper.java:137)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at android.app.ActivityThread.main(ActivityThread.java:4745)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at java.lang.reflect.Method.invokeNative(Native Method)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at java.lang.reflect.Method.invoke(Method.java:511)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-30 11:38:23.233: E/AndroidRuntime(17284):    at dalvik.system.NativeStart.main(Native Method)
 04-30 11:38:23.233: E/AndroidRuntime(17284): Caused by: java.lang.NullPointerException
 04-30 11:38:23.233: E/AndroidRuntime(17284):   at com.example.imageurl.MainActivity.onCreate(MainActivity.java:59)
 04-30 11:38:23.233: E/AndroidRuntime(17284):   at android.app.Activity.performCreate(Activity.java:5008)
 04-30 11:38:23.233: E/AndroidRuntime(17284):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
 04-30 11:38:23.233: E/AndroidRuntime(17284):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
</code></pre>
