gpt4 book ai didi

android - 您必须传入一个非空 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:18 25 4
gpt4 key购买 nike

我最近将我的项目更新为 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) 

我正在使用包含导航 View 的抽屉导航布局。此导航 View 包含我显示的页眉布局,事实证明我注释掉的代码用于显示页眉布局的图片。所以有什么在新的库更新中发生了变化?

最佳答案

导航 View 似乎存在问题。 NavigationView findViewById can't find header view

当前的修复/变通方法是使用查找页眉布局。

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

关于android - 您必须传入一个非空 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33176037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com