You must pass a non-null View

I recently updated my project in Android Support Library 23.1, and this part of my code now gives an error.

He worked before updating and commented only on this part, which allows me to run the application normally. What exactly is wrong or has changed?

Glide.with(getApplicationContext()) .load(R.drawable.banner) .fitCenter() .override(width, height / 2) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(back); if (picture != null) { Glide.with(getApplicationContext()) .load(picture) .fitCenter() .override(width / 2, height / 2) .into(profile); } else { Glide.with(getApplicationContext()) .load(R.drawable.profile_p) .fitCenter() .override(width / 2, height / 2) .into(profile); } 

This is an error log.

  10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: FATAL EXCEPTION: main 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: Process: atsystems.cal, PID: 16313 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{atsystems.cal/atsystems.cal.MainActivity}: java.lang.IllegalArgumentException: You must pass in a non null View 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: You must pass in a non null View 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at atsystems.cal.MainActivity.onCreate(MainActivity.java:74) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-16 22:41:27.238 16313-16313/atsystems.cal E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

I am using a navigation box layout that contains a navigation view. This navigation view contains the header layout that I am showing, and as it turned out, the code I commented on is used to display images for the header layout. changed in a new library update?

+8
android view navigation appcompat
source share
1 answer

It would seem that there is a problem with the navigation view. NavigationView findViewById cannot find title view

The current fix / workaround is to search for a header layout using.

 final NavigationView mNavigationView = (NavigationView) findViewById(R.id.navigation_view); final View headerLayout = mNavigationView.inflateHeaderView(R.layout.header); 

Once this is done, you can refer to each element in the header layout like this.

 final ImageView profile = (ImageView) headerLayout.findViewById(R.id.profile_image); 
+10
source share

All Articles