I designed a widget for my application that worked already, but now when I click on the widget, I encounter the following error.Error occurred
My code
@Override
protected void onResume() {
super.onResume();
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
//ByteArrayOutputStream out = new ByteArrayOutputStream();
//bitmap.compress(Bitmap.CompressFormat.PNG,90,out);
v1.setDrawingCacheEnabled(false);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(bitmap)
.setContentTitle("title")
.setContentText("message:")
.setAutoCancel(true)
.setOngoing(false)
.setTicker("ticker");
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(123456, builder.build());
}
Error occurred:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createBitmap(Bitmap.java:771)
at com.blackswan.shaghayeghaccounting.transactions.TransparentQuickActionActivity.onResume(TransparentQuickActionActivity.java:113)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1287)
at android.app.Activity.performResume(Activity.java:7015)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4210)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4323)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3426)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
04-04 16:10:27.445 25895-25895/com.blackswan.shaghayeghaccounting E/AndroidRuntime: FATAL EXCEPTION: main Process: com.blackswan.shaghayeghaccounting, PID: 25895 java.lang.RuntimeException: Unable to resume activity {com.blackswan.shaghayeghaccounting/com.blackswan.shaghayeghaccounting.transactions.TransparentQuickActionActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4221) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4323) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3426) at android.app.ActivityThread.access$1100(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7325) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.graphics.Bitmap.createBitmap(Bitmap.java:771)