我正在尝试将图像IMAGEVIEW从不在我Drawable的Base64字符串中转换为下面的代码,但它导致了NullPointerException.
这是代码:
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);
Run Code Online (Sandbox Code Playgroud)
这是logcat所说的:
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: …Run Code Online (Sandbox Code Playgroud) android ×1