我正在开发一个安卓应用程序的新版本,这是一些以前的开发人员发布的包名,比如com.mycompany.MyApp,我必须使用相同的包名。
在我的项目中,我使用了数据绑定库( Data ),它需要用小写符号表示包名,而且我一直收到“com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBinding”:java.lang.IllegalArgumentException:无法猜测“
然后根据官方文件,还有一些这样的条目,我已经把
<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
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
<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>
自动生成类
package com.mycompany.MyApp.databinding;
public class MyFragmentRecyclerViewItemBindingImpl extends MyFragmentRecyclerViewItemBinding {
...
发布于 2019-09-30 16:08:23
"java.lang.IllegalArgumentException: couldn't make a guess for com.mycompany.MyApp.databinding.MyFragmentRecyclerViewItemBindingImpl"
基本上,这个例外规定,不能简单地在包名中使用大写名称(Camel Hump大写)来处理通过数据绑定中的数据变量的对象。
因此,解决方法是在较低的情况下使用包名来解决这个问题。对于O.P.的情况,可以通过将MyApp
重命名为myapp
或其他方便的方法来解决。
因此,最终结果将是:
<data class="com.mycompany.myapp.databinding.MyFragmentRecyclerViewItemBinding">
https://stackoverflow.com/questions/58169816
复制相似问题