您必须传入非空视图

我最近更新了我的项目到Android支持库23.1,这段代码现在给出了一个错误。

它正在更新和评论,只是这部分允许我运行应用罚款。究竟是错误还是有变化?

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

这是错误日志。

  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) 

我正在使用一个包含导航视图的导航抽屉布局。这个导航视图包含我显示的标题布局,事实certificate,我注释到的代码是用来显示标题布局的图片。因此,新库更新?

Solutions Collecting From Web of "您必须传入非空视图"

似乎有关于导航视图的问题。 NavigationView findViewById找不到标题视图

目前的修复/解决方法是使用find页眉布局。

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

一旦完成,您可以像这样引用标题布局中的每个元素。

 final ImageView profile = (ImageView) headerLayout.findViewById(R.id.profile_image);