首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >camel包名时的数据绑定库

camel包名时的数据绑定库
EN

Stack Overflow用户
提问于 2019-09-30 14:18:55
回答 1查看 920关注 0票数 2

我正在开发一个安卓应用程序的新版本,这是一些以前的开发人员发布的包名,比如com.mycompany.MyApp,我必须使用相同的包名。

在我的项目中,我使用了数据绑定库( Data ),它需要用小写符号表示包名,而且我一直收到“com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding”:java.lang.IllegalArgumentException:无法猜测“

然后根据官方文件,还有一些这样的条目,我已经把

代码语言:javascript
运行
复制
<data class="com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding" ></data> 

my_fragment_recycler_view_item.xml中布局顶部的定义

现在我可以在MyFragmentRecyclerViewItemBinding中导入类MyRecyclerViewFragment.kt并访问视图元素等,但是由于无法编译自动生成的类MyFragmentRecyclerViewItemBindingImpl,所以无法编译该项目。

Gradle给出了“com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBindingImpl”:无法猜测“,我可以看到MyFragmentRecyclerViewItemBindingImpl类中的错误,因为”无法从最终的'com.mycompany.MyApp.MyFragmentRecyclerViewItemBinding'“继承”

我想这是因为在Kotlin,所有的类都是默认的决赛,但是我还是被困在这里了。你有什么建议吗?或者你能看出我做错了什么吗?

预先感谢所有的阅读,评论和回答。我不能直接分享代码,但是符号代码如下所示;

MyRecyclerViewFragment.kt

代码语言:javascript
运行
复制
import com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding

class MyRecyclerViewFragment: Fragment()
{
 override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val fragmentIntroSlidePage = MyFragmentRecyclerViewItemBinding.inflate(inflater,
            container, false)
        //TODO ..
        return fragmentIntroSlidePage.root
    }
}

my_fragment_recycler_view_item.xml

代码语言:javascript
运行
复制
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data class="com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding">

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/myBgColor"
        android:orientation="vertical">


        <ImageView
            android:id="@+id/slide_bg_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/intro_slide_1_text"
            android:scaleType="fitXY"
            android:src="@drawable/intro_slide_01"
            app:layout_constraintHeight_min="150dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

自动生成类

代码语言:javascript
运行
复制
package com.mycompany.MyApp.databinding;

public class MyFragmentRecyclerViewItemBindingImpl extends MyFragmentRecyclerViewItemBinding  {
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-30 16:08:23

代码语言:javascript
运行
复制
"java.lang.IllegalArgumentException: couldn't make a guess for com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBindingImpl"

基本上,这个例外规定,不能简单地在包名中使用大写名称(Camel Hump大写)来处理通过数据绑定中的数据变量的对象。

因此,解决方法是在较低的情况下使用包名来解决这个问题。对于O.P.的情况,可以通过将MyApp重命名为myapp或其他方便的方法来解决。

因此,最终结果将是:

代码语言:javascript
运行
复制
<data class="com.mycompany.myapp.databinding.MyFragmentRecyclerViewItemBinding">
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58169816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档