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

我想将我的 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)


森栏
浏览 77回答 1
1回答

德玛西亚99

该错误表明它找不到带有单个 String 参数的名为 returnDiffFromCurrentDate 的方法,只要它在您的 CommonUtils 类中。然后问题出在 viewModel.mDate 中,它似乎是一个字符串,而不是一个很长的字符串您应该使用任何其他方法将其转换为 long 或更改 returnDiffFromCurrentDate 以期待一个 String
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java