Blurry
Blurry copied to clipboard
NullPointerException
I'm using this in onCreate and getting crash.
MainActivity.java
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.nav); Blurry.with(this).radius(25).sampling(2).onto(viewGroup);
activity_main.xml
<LinearLayout android:id="@+id/nav" android:alpha="0.95" android:layout_width="@dimen/navi_width" android:layout_height="match_parent" android:orientation="vertical" android:layout_gravity="start" android:layout_marginTop="@dimen/tab_height" android:background="@drawable/navigation" />
LogCat
08-31 15:04:31.126 25687-25687/de.test.demo E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{de.test.demo/de.test.demo.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309) at android.app.ActivityThread.access$700(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5317) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at jp.wasabeef.blurry.internal.Blur.rs(Blur.java:38) at jp.wasabeef.blurry.Blurry$Composer.onto(Blurry.java:107) at de.test.demo.MainActivity.onCreate(MainActivity.java:120) at android.app.Activity.performCreate(Activity.java:5326) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309) at android.app.ActivityThread.access$700(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5317) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method)
@ucargames
is ViewGroup
null?
@wasabeef I caught the same issue. The ViewGroup is not null. I have printed it to logcat.
I have looked at rs method. I am not sure about these lines:
view.destroyDrawingCache();
Bitmap cache = view.getDrawingCache();
The cache has been destroyed before we can get the cache? Correct me if I am wrong.
add this to your build.gradle app
android { defaultConfig { renderscriptTargetApi 23 renderscriptSupportModeEnabled true } }
@Ralphilius
We have to clean the cache.
I'ḿ having the same problem, is there any solution?
@anapsil https://github.com/wasabeef/glide-transformations https://github.com/wasabeef/picasso-transformations https://github.com/wasabeef/fresco-processors
I had the same problem.
This problem cause is maybe the view isn't render yet when called "Blurry.with(context).onto(viewGroup);". My solution is using ViewTreeObserver().
viewGroup.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
viewGroup.getViewTreeObserver().removeOnPreDrawListener(this);
Blurry.with(context).radius(25).sampling(2).onto(viewGroup);
return true;
}
});
Hey @wasabeef, same problem here, getDrawingCache
returns null
and crash:
Bitmap cache = view.getDrawingCache();
@yhirano suggests a nice solution that works for me. Would be nice if the library itself can handle this though. I read this SO, which has a good explanation too about why the getDrawingCache
is null in some cases.