Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android camel case包名称时的数据绑定库_Android_Kotlin_Data Binding - Fatal编程技术网

Android camel case包名称时的数据绑定库

Android camel case包名称时的数据绑定库,android,kotlin,data-binding,Android,Kotlin,Data Binding,我正在开发一个android应用程序的新版本,该应用程序已由一些以前的开发人员在市场上发布,其软件包名为com.mycompany.MyApp,我必须使用相同的软件包名 在我的项目中,我使用了数据绑定库,它需要对包名使用小写符号,并且我收到了“java.lang.IllegalArgumentException:无法猜测com.mycompany.MyApp.databinding.myFragmentRecycleServiceItemBinding” 然后根据官方文件和SO中的一些条目, 我

我正在开发一个android应用程序的新版本,该应用程序已由一些以前的开发人员在市场上发布,其软件包名为com.mycompany.MyApp,我必须使用相同的软件包名

在我的项目中,我使用了数据绑定库,它需要对包名使用小写符号,并且我收到了“java.lang.IllegalArgumentException:无法猜测com.mycompany.MyApp.databinding.myFragmentRecycleServiceItemBinding”

然后根据官方文件和SO中的一些条目, 我把

<data class="com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding" ></data> 
my_fragment_recycler_view_item.xml

<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>
基本上,这个异常表明,对于通过数据绑定中的数据变量传递的对象,不能简单地在包名中使用大写名称(驼峰大小写)

所以,解决方案是将包名改为小写,以消除这个问题。对于O.P.的情况,可以通过将
MyApp
重命名为
MyApp
或其他方便的方式来解决

因此,最终结果将是:

<data class="com.mycompany.myapp.databinding.MyFragmentRecyclerViewItemBinding">


您可以将
MyApp
的目录名更改为您想要的任何名称,只需确保不从清单文件或Gradle更改applicationId即可。通常,最好的做法是让包名和应用程序id都处于空闲状态,但如果不遵循该规则,则不会有任何伤害。更改包名部分效果很好。非常感谢你。对于未来的读者,让我澄清一下解决方案。当我们在fragment.xml中使用标记添加自定义类定义时,我们不必使用与项目相同的包名。我们可以提供一个自定义的包名。如果你不介意回答,我会同意的。再次感谢。一个可能的问题是,如果用户在启动器中已经有一个指向主活动的应用程序快捷方式,那么如果活动的包名更改,它将被破坏。我没有更改任何活动包名,我只是更改了自动生成的绑定类目标包
package com.mycompany.MyApp.databinding;

public class MyFragmentRecyclerViewItemBindingImpl extends MyFragmentRecyclerViewItemBinding  {
...
"java.lang.IllegalArgumentException: couldn't make a guess for com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBindingImpl"
<data class="com.mycompany.myapp.databinding.MyFragmentRecyclerViewItemBinding">