为了账号安全,请及时绑定邮箱和手机立即绑定

无法将 textview 绑定到公共不可实例化最终类中的静态方法

无法将 textview 绑定到公共不可实例化最终类中的静态方法

森栏 2023-03-02 15:19:48
我想将我的 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


查看完整回答
反对 回复 2023-03-02
  • 1 回答
  • 0 关注
  • 60 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信