gpt4 book ai didi

java - 在抽屉布局中使用 Glide 从 Url 使用 CircularImage View 时,应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 09:44:58 28 4
gpt4 key购买 nike

我正在使用 Github library 中的 GlideCircularImageview获取图像 URL 并将其显示到 DrawerlayoutImageView 中。它工作正常并且图像已加载。当我打开应用程序并关闭应用程序而不打开 NavigationDrawer 时,它不会产生任何错误,但是当我打开应用程序并打开 DrawerLayout 时,然后按后退按钮关闭应用程序崩溃并出现以下错误:

 Process: com.mscphysics.plusacademy, PID: 21955
java.lang.RuntimeException: Unable to destroy activity {com.mscphysics.plusacademy/com.mscphysics.plusacademy.PaidUser.Activity.Home}: java.lang.NullPointerException
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3498)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3516)
at android.app.ActivityThread.access$1400(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5018)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:589)
at com.pkmmte.view.CircularImageView.refreshBitmapShader(CircularImageView.java:341)
at com.pkmmte.view.CircularImageView.invalidate(CircularImageView.java:262)
at android.widget.ImageView.setImageDrawable(ImageView.java:426)
at com.bumptech.glide.request.target.DrawableImageViewTarget.setResource(DrawableImageViewTarget.java:28)
at com.bumptech.glide.request.target.DrawableImageViewTarget.setResource(DrawableImageViewTarget.java:10)
at com.bumptech.glide.request.target.ImageViewTarget.setResourceInternal(ImageViewTarget.java:127)
at com.bumptech.glide.request.target.ImageViewTarget.onLoadCleared(ImageViewTarget.java:97)
at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:319)
at com.bumptech.glide.manager.RequestTracker.clearRemoveAndMaybeRecycle(RequestTracker.java:79)
at com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle(RequestTracker.java:66)
at com.bumptech.glide.RequestManager.untrack(RequestManager.java:603)
at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:571)
at com.bumptech.glide.RequestManager.clear(RequestManager.java:559)
at com.bumptech.glide.RequestManager.onDestroy(RequestManager.java:303)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy(ActivityFragmentLifecycle.java:65)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy(SupportRequestManagerFragment.java:194)
at android.support.v4.app.Fragment.performDestroy(Fragment.java:2588)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1566)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3244)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3235)
at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:265)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:390)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
at android.app.Activity.performDestroy(Activity.java:5410)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3485)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3516) 
at android.app.ActivityThread.access$1400(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5018) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 

我的抽屉导航方法是

public void updateNavHeader() {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
TextView navUsername = headerView.findViewById(R.id.nav_username);
TextView navUserMail = headerView.findViewById(R.id.nav_user_mail);
ImageView navUserPhot = headerView.findViewById(R.id.nav_user_photo);

navUserMail.setText(currentUser.getEmail());
navUsername.setText(currentUser.getDisplayName());

// now we will use Glide to load user image
// first we need to import the library
Glide.with(this).load(currentUser.getPhotoUrl()).into(navUserPhot);
}

我的 xml 是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="#ffffff">

<com.pkmmte.view.CircularImageView
android:id="@+id/nav_user_photo"
android:layout_width="64dp"
android:layout_height="64dp"
android:contentDescription="@string/nav_header_desc"
app:srcCompat="@mipmap/ic_launcher_round"
app:border="true"
app:border_color="#EEEEEE"
app:border_width="4dp"
app:shadow="true" />


<TextView
android:textColor="#000"
android:id="@+id/nav_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
android:textColor="#000"
android:id="@+id/nav_user_mail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />

</LinearLayout>

任何人都可以解释为什么它在打开应用程序以及打开抽屉导航并关闭应用程序后抛出错误,但在仅打开应用程序并简单地关闭它而不打开抽屉时不会抛出错误。

最佳答案

请使用这个CircleImageView library反而。这是我在许多圆形图像项目中看到的库这应该可以解决你的问题

这是一个例子

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>

关于java - 在抽屉布局中使用 Glide 从 Url 使用 CircularImage View 时,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56735946/

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