草庐IT

android - e : [kapt] An exception occurred: android. databinding.tool.util.LoggedErrorException: 发现数据绑定(bind)错误

coder 2023-05-09 原文

我已启用数据绑定(bind),但在执行代码时出现此错误。

错误

e: [kapt] 发生异常:android.databinding.tool.util.LoggedErrorException: 发现数据绑定(bind)错误。

我为该类创建了一个 fragment 类和 XML。 我能够导入 datbindingutil 类。

我已经完成了重建/与 gradle 文件同步/使缓存无效并重新启动,但没有任何效果。

xml

<layout>

<!--suppress AndroidUnknownAttribute -->
<data class=".databinding.ProfileFragmentBinding">

    <variable
        name="user"
        type="com.sample.sample.user.User" />

    <variable
        name="vm"
        type="com.sample.sample.user.UserViewModel" />

    <variable
        name="handler"
        type="com.sample.sample.user.profile.ProfileFragment" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profileIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/medium"
        android:layout_marginTop="@dimen/medium"
        android:contentDescription="@null"
        android:src="@mipmap/ic_launcher_round"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:url="@{user.avatarUrl}" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="@+id/profileIV"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/profileIV">

        <TextView
            android:id="@+id/profileNameLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/myriad_pro_semibold"
            android:text="@{user.name}"
            android:textColor="@color/black_transparent_de"
            android:textSize="@dimen/text_regular"
            tools:text="NAME" />

        <TextView
            android:id="@+id/badgeLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:fontFamily="@font/myriad_pro_semibold"
            android:text="@{user.badge}"
            android:textColor="@color/grey_000000"
            android:textSize="@dimen/text_regular"
            tools:text="Superman" />

        <TextView
            android:id="@+id/profile_Label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:fontFamily="@font/roboto_bold"
            android:text="@{user.badge}"
            android:textColor="@color/green_39b54a"
            android:textSize="@dimen/text_small"
            tools:text="farmer_v1" />

    </LinearLayout>

    <ImageView
        android:id="@+id/badgeIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/medium"
        android:layout_marginTop="@dimen/medium"
        android:contentDescription="@null"
        android:src="@mipmap/ic_launcher"
        app:error="@{@drawable/ic_profile_default_grey_24dp}"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:placeholder="@{@drawable/ic_profile_default_grey_24dp}"
        app:url="@{user.badgeUrl}" />

    <ImageView
        android:id="@+id/locationPinIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/medium"
        android:contentDescription="@null"
        android:src="@drawable/ic_location_pin"
        app:layout_constraintStart_toStartOf="@+id/profileIV"
        app:layout_constraintTop_toBottomOf="@+id/profileIV" />

    <TextView
        android:id="@+id/profileAddressTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/narrow"
        android:fontFamily="@font/roboto"
        android:textColor="@color/grey_000000"
        app:layout_constraintBottom_toBottomOf="@+id/locationPinIV"
        app:layout_constraintLeft_toRightOf="@+id/locationPinIV"
        app:layout_constraintTop_toTopOf="@+id/locationPinIV"
        tools:text="bangalore, Karnataka" />

    <ImageView
        android:id="@+id/dobIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/standard"
        android:layout_marginTop="@dimen/medium"
        android:contentDescription="@null"
        android:src="@drawable/ic_dob"
        app:layout_constraintLeft_toRightOf="@+id/profileAddressTV"
        app:layout_constraintTop_toBottomOf="@+id/profileIV" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/narrow"
        android:fontFamily="@font/roboto"
        android:textColor="@color/grey_000000"
        app:layout_constraintBottom_toBottomOf="@+id/locationPinIV"
        app:layout_constraintLeft_toRightOf="@+id/dobIV"
        app:layout_constraintTop_toTopOf="@+id/locationPinIV"
        tools:text="born on 01/01/2000" />

    <TextView
        android:id="@+id/activityLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/big"
        android:fontFamily="@font/myriad_pro_semibold"
        android:text="@string/activities"
        android:textColor="@color/black_transparent_de"
        android:textSize="@dimen/text_regular"
        app:layout_constraintStart_toStartOf="@+id/profileIV"
        app:layout_constraintTop_toBottomOf="@+id/locationPinIV" />

    <View
        android:id="@+id/dividerV"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginEnd="@dimen/small"
        android:layout_marginStart="@dimen/small"
        android:layout_marginTop="@dimen/regular"
        android:background="@color/grey_000000"
        app:layout_constraintTop_toBottomOf="@+id/activityLabel" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@+id/dividerV">

        <!--<com.google.android.material.tabs.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:pager="@{(pager)}"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/black"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/black"
            app:tabTextAppearance="@style/CustomTextTab"
            app:tabTextColor="#b4ffffff" />

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tablayout"
            app:handler="@{handler}"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->

    </RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

    class ProfileFragment : Fragment() {
    @Inject
    lateinit var mFactory: ViewModelProvider.Factory
    private lateinit var mBinding: ProfileFragmentBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_profile, container, false);
        return mBinding.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val vm: UserViewModel = getViewModel(mFactory)
        mBinding.vm = vm
        //mBinding.handler = this
        //mBinding.setLifecycleOwner(this)
    }

    /*@BindingAdapter("bind:handler")
    fun bindViewPagerAdapter(view: ViewPager, activity: MainActivity) {
        val adapter = ProfilePagerAdapter(view.context, activity.supportFragmentManager)
        view.adapter = adapter
    }

    @BindingAdapter("bind:pager")
    fun bindViewPagerTabs(view: TabLayout, pagerView: ViewPager) {
        view.setupWithViewPager(pagerView, true)
    }*/
}

最佳答案

在我的情况下,当鼠标悬停在构建输出中的该行时,我能够找到它,如下所示:

没有悬停:

悬停:

他们显示错误的方式真的很可惜,对于有史以来最简单的错误,我尝试了 10 种不同的解决方案,同时使缓存无效......

更新:

你也可以点击这里:

你会得到这样的东西:

这是关于错误的非常详细的信息,我在 7 年的 Android 开发中错过了这个按钮:D

关于android - e : [kapt] An exception occurred: android. databinding.tool.util.LoggedErrorException: 发现数据绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53166846/

有关android - e : [kapt] An exception occurred: android. databinding.tool.util.LoggedErrorException: 发现数据绑定(bind)错误的更多相关文章

  1. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  2. ruby - ruby 中的 TOPLEVEL_BINDING 是什么? - 2

    它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput

  3. ruby-on-rails - 创建 ruby​​ 数据库时惰性符号绑定(bind)失败 - 2

    我正在尝试在Rails上安装ruby​​,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf

  4. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  5. ruby - ruby 中绑定(bind)对象的实际使用 - 2

    昨晚,我在思考我认为是高级ruby​​语言的功能,即Continuations(callcc)和Bindingobjects。我的意思是高级,因为我有静态类型的oo语言背景(C#、Java、C++),我最近才发现ruby​​,所以这些语言特性对我来说不是很熟悉。我想知道这些语言功能在现实世界中的用途是什么。根据我的经验,一切都可以用静态类型的oo语言来完成,但有时我不太同意。我想我在阅读SamRuby的那篇好文章时发现了Continuation的美妙之处/兴趣:http://www.intertwingly.net/blog/2005/04/13/Continuations-for-C

  6. ruby - svn ruby​​ 绑定(bind)是否作为 gem 提供? - 2

    我看到有几十个与svn相关的gem,但是我在其中任何一个上找到的少量文档表明它们是命令行包装器和杂项帮助程序。(svn命令、svn钩子(Hook)等)我在野外看到过执行以下操作的代码:require'svn/core'和SVN.Repos.add(...),但该模块的作者通过apt-get提取了他的svnruby​​工具。这对我来说不是一个选择,因为我正在开发一个windows/osx工具。Thispage列出了一些项目,但特别是,我需要一些可以访问svn+ssh存储库的东西,而且我没有时间花一半的时间来挖掘文档-十几个项目,试图引导每一个。我在寻找哪个gem?从那里开始,我很乐意挖掘

  7. ruby-on-rails - 如何将 rvm 与 eclipse 的设置绑定(bind) - 2

    我正在为不同的应用程序使用多个ruby​​实例和gemset进行开发。为了在我的ruby​​版本和gemset之间切换,我使用.rvmrc文件。我还使用带有radrails插件的Eclipse作为我的开发工具。有什么方法可以让eclipse使用rvm在不同的gemsets和ruby​​版本之间自动切换? 最佳答案 Gointoyourprojectdirectoryandcreateafilecalled.rvmrccontainingtheline:rvmuseruby-1.8.7-p330@testing--default(or

  8. ruby-on-rails - 是否有可能发现 Ruby on Rails 应用程序中未使用哪些类? - 2

    在我们的项目中,我们有一些“被遗忘的”类存在了很长一段时间。那些类已被其他类替代,但我们忘记删除它们。是否有一些自动化的方法/工具可以发现Ruby{onRails}应用程序中没有使用哪些类?谢谢! 最佳答案 这个问题已经被提出了很多次,但是最好的答案都在这里:FindunusedcodeinaRailsapp我个人喜欢日志解析:https://stackoverflow.com/a/14161807但在任何情况下,您都可以创建自己的记录器,扩展ActiveRecord::Base以创建一个观察器,该观察器将最常用的模块存储在数据库中

  9. ruby-on-rails - Rails Controller 操作是否隐式定义事务绑定(bind)? - 2

    给定以下代码:defcreate@something=Something.new(params[:something])thing=@something.thing#anothermodel#modificationofattributesonboth'something'and'thing'omitted#doIneedtowrapitinsideatransactionblock?@something.savething.saveendcreate方法是隐式包装在ActiveRecord事务中,还是需要将其包装到事务block中?如果我确实需要包装它,这是最好的方法吗?

  10. ruby - 元编程:如何发现对象的真实类? - 2

    我在用Ruby元编程开玩笑,我写了这段代码:classClassdef===(other)other.kind_of?(self)endendclassFakeClassdefinitialize(object)methods.each{|m|eval"undef#{m}"ifm.to_sym!=:methods}define=procdo|m|eval(这会创建一个模拟对象的假类。看:a=FakeClass.new(1)#=>1a.class#=>Fixnuma.methods#=>ReturnallFixnummethodsa+1#=>2(isnotaFakeClass)Fixnu

随机推荐