亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

RecycleViewAdapter 在加載它的項目時獲取 null 異常

RecycleViewAdapter 在加載它的項目時獲取 null 異常

慕田峪7331174 2023-02-23 10:50:47
在我的應用程序中,我有一個活動(主要活動),其中有一個顯示片段的 ViewPager?,F在我有一個片段,里面有一個 RecyclerView。這個 RecyclerView 應該顯示“目標”對象列表。每次我運行該應用程序時,它都會崩潰,說它有一個空問題,我認為這可能是因為寫東西的順序。我試過然后更改順序,在互聯網上搜索其他可能的問題,但沒有成功。fragment_active_goals.xml:<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".ActiveGoals">    <androidx.recyclerview.widget.RecyclerView        android:id="@+id/activeGoalsRecyclerView"        android:layout_width="match_parent"        android:layout_height="match_parent" /></FrameLayout>goals_list_item.xml:<?xml version="1.0" encoding="utf-8"?><androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:id="@+id/goalCardParent"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="wrap_content"    app:cardCornerRadius="0dp"    android:clickable="true"    android:focusable="true"    android:background="@color/cardview_light_background">    <androidx.constraintlayout.widget.ConstraintLayout        android:layout_width="match_parent"        android:layout_height="match_parent">        <com.github.abdularis.civ.CircleImageView            android:id="@+id/goalImage"            android:layout_width="150dp"            android:layout_height="0dp"            app:layout_constraintDimensionRatio="1:1"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintTop_toTopOf="parent"            app:layout_constraintBottom_toBottomOf="parent"            app:layout_constraintVertical_bias="0.5"            android:src="@drawable/active_brain_drawing"/>
查看完整描述

2 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

剛剛想通了!問題出在 goal_list_item.xml (v26) 中……對象的 ID 在某種程度上有所不同,代碼無法通過 ID 找到正確的對象。抱歉打擾了,我的壞XD謝謝大家幫助我!



查看完整回答
反對 回復 2023-02-23
?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

我知道這是一個自定義視圖,但如果它擴展了一個普通的 ImageView,你應該改為嘗試這個,因為你使用的是可繪制 ID

holder.goalImage.setImageDrawable(mContext.getDrawable(goals.get(position).getImageId()));


查看完整回答
反對 回復 2023-02-23
  • 2 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號