我想將我的 utils 類之一綁定到文本視圖。我在數據字段中包含了我的 Utils 類。當我運行該應用程序時,出現錯誤,例如未找到該方法我的 xml 文件<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <import type="PACKAGE_NAME.utils.CommonUtils"/> <variable name="viewModel" type="PACKAGE_NAME.PACKAGE_UI_PATH.RecordItemViewModel" /> </data> <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:elevation="5dp" app:cardElevation="5dp" tools:targetApi="lollipop"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> </com.google.android.material.card.MaterialCardView> </layout>我收到以下錯誤消息發現數據綁定錯誤。****/ 數據綁定錯誤 ****msg: 在類 PACKAGE_NAME.utils.CommonUtils 中找不到方法 returnDiffFromCurrentDate(java.lang.String)
1 回答

德瑪西亞99
TA貢獻1770條經驗 獲得超3個贊
該錯誤表明它找不到帶有單個 String 參數的名為 returnDiffFromCurrentDate 的方法,只要它在您的 CommonUtils 類中。
然后問題出在 viewModel.mDate 中,它似乎是一個字符串,而不是一個很長的字符串
您應該使用任何其他方法將其轉換為 long 或更改 returnDiffFromCurrentDate 以期待一個 String
添加回答
舉報
0/150
提交
取消