0
2021-08-30 22:31:54.727 15117-15117/com.eosphorus.flockflairapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.eosphorus.flockflairapp, PID: 15117
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eosphorus.flockflairapp/com.eosphorus.flockflairapp.DisplayQuestions}: java.lang.NullPointerException: Argument must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6806)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
     Caused by: java.lang.NullPointerException: Argument must not be null
        at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:31)
        at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:25)
        at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:651)
        at com.eosphorus.flockflairapp.DisplayQuestions.onCreate(DisplayQuestions.java:116)
        at android.app.Activity.performCreate(Activity.java:7224)
        at android.app.Activity.performCreate(Activity.java:7213)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:201) 
        at android.app.ActivityThread.main(ActivityThread.java:6806) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
  • Code
<ImageView
            android:id = "@+id/imageView"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content" />
        ImageView imageView = findViewById(R.id.imageView);

        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background);

        Glide.with(this).load("https://www.tutorialspoint.com/images/tp-logo-diamond.png").apply(options).into(imageView);

Lav Sharma
  • 327
  • 1
  • 5
  • 23
  • `imageView` is clearly null. *Why* is unclear. Can you post a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – Joachim Sauer Aug 30 '21 at 17:18
  • @joachim Sauer No it's not null... – Vatsal Dholakiya Aug 30 '21 at 17:43
  • 1
    @Lav Sharma please use like https://stackoverflow.com/a/44199289/12660050 options put into apply directly... – Vatsal Dholakiya Aug 30 '21 at 17:49
  • @VatsalDholakiya: well, the stack trace is cleary says "Argument must not be null" and the method you call is `RequestBuilder.into` and if you check the [RequestBuilder source](https://github.com/bumptech/glide/blob/master/library/src/main/java/com/bumptech/glide/RequestBuilder.java) then you'll see that the first thing that `into()` does is call `Preconditions.checkNotNull(view);`. I'm very confident that the value that you pass to `into()` is null for some reason. You can chose to not believe that, but that doesn't mean I'm wrong. – Joachim Sauer Aug 30 '21 at 18:23
  • Yes, it is null pointer exception you are right that there is null at into() but not because of nothing there is pass. I think It is because of something wrong in options which is passed in apply(). – Vatsal Dholakiya Aug 30 '21 at 18:32
  • @VatsalDholakiya: that's not what the code suggests. Why are you so convinced that `imageView` is not `null`? Have you looked at the line in a debugger? Logged the value just before using it? – Joachim Sauer Aug 30 '21 at 18:34
  • I am not saying that imageview is not null (May be from link image is not fetching. )I am saying that imageview is passed in into(). – Vatsal Dholakiya Aug 30 '21 at 18:37
  • And to proof my case: I'd bet that you're using version 4.7.0 of Glide, because [that's the version where the `Preconditions.checkNotNull(view)` call is exactly on line 651, as indicated by your stacktrace](https://github.com/bumptech/glide/blob/v4.7.0/library/src/main/java/com/bumptech/glide/RequestBuilder.java#L651). – Joachim Sauer Aug 30 '21 at 18:37
  • The problem is the value that you pass to `into()` is null. That value is stored in `imageView`. Therefore `imageView` is `null`. Find out why and fix it. – Joachim Sauer Aug 30 '21 at 18:38
  • @VatsalDholakiya [this](https://stackoverflow.com/questions/44198856/glide-does-not-resolve-its-method/44199289#44199289) solved my issue. You can post it as an answer so that I can accept it. – Lav Sharma Aug 31 '21 at 08:31
  • great, answer is posted. – Vatsal Dholakiya Aug 31 '21 at 08:50

1 Answers1

1

Add .apply(new RequestOptions() to continue with latest version. Just Replace below code:

Glide
 .with(this)
 .load(R.drawable.image_default_profile_picture)
 .apply(new RequestOptions()
 .placeholder(R.mipmap.ic_launcher_background)
 .fitCenter())
 .into(imageView);
Vatsal Dholakiya
  • 545
  • 4
  • 19