Blurry icon indicating copy to clipboard operation
Blurry copied to clipboard

NullPointerException

Open ucargames opened this issue 9 years ago • 8 comments

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 avatar Aug 31 '15 13:08 ucargames

@ucargames

is ViewGroup null?

wasabeef avatar Sep 03 '15 11:09 wasabeef

@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.

ralphilius avatar Sep 06 '15 13:09 ralphilius

add this to your build.gradle app

android { defaultConfig { renderscriptTargetApi 23 renderscriptSupportModeEnabled true } }

mahmoudco avatar Sep 07 '15 09:09 mahmoudco

@Ralphilius

We have to clean the cache.

wasabeef avatar Sep 07 '15 11:09 wasabeef

I'ḿ having the same problem, is there any solution?

anapsil avatar Nov 05 '15 19:11 anapsil

@anapsil https://github.com/wasabeef/glide-transformations https://github.com/wasabeef/picasso-transformations https://github.com/wasabeef/fresco-processors

wasabeef avatar Nov 06 '15 01:11 wasabeef

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;
    }
});

yhirano avatar Nov 18 '15 15:11 yhirano

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.

yzhong52 avatar Nov 25 '16 20:11 yzhong52