Data Binding的报错集合: 例如Error:(10, 54) 错误: 程序包com.kodulf.recyclerviewdatabinding.databinding不存在

报错0:找不到MainActivityBinding

官网上面是:MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);

//应该是,官网上面有问题了,应该是ActivityMainBinding,而不是 MainActivityBinding

感谢HoHohong的提醒,应该是这样的:这个Binding类是根据XML名字生成的,官网上用MainActivityBinding是因为它的XML名字为main_activity.xml;但我们在AS新建项目时名字默认为activity_main,所以才得用ActivityMainBinding



报错1程序包com.kodulf.recyclerviewdatabinding.databinding不存在


C:\AdroidProjects\RecyclerViewDataBinding\app\src\main\java\com\kodulf\recyclerviewdatabinding\MainActivity.java

Error:(10, 54) 错误: 程序包com.kodulf.recyclerviewdatabinding.databinding不存在
C:\AdroidProjects\RecyclerViewDataBinding\app\src\main\res\layout\activity_main.xml
Error:(18, 35) Could not find accessor com.kodulf.recyclerviewdatabinding.User.isFriend 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.

Information:BUILD FAILED



报错分析:MainActivity.java  里面出错的。不能够导入 com.kodulf.recyclerviewdatabinding.databinding 这个包,

com.kodulf.recyclerviewdatabinding.databinding这个包是根据activity_main.xml来自动生成的,


既然找不到这个包,说明activity_main.xml 里面有问题,

而这个问题又是因为

Error:(18, 35) Could not find accessor com.kodulf.recyclerviewdatabinding.User.isFriend 

所以应该是User的类里面的isFriend的属性有问题,

最后我发现了,

我的get方法里面的对应的isFriend的应该是getIsFriend,而我的方法里面确实getFriend



报错2: 与元素类型 "variable" 相关联的 "type" 属性值不能包含 '<' 字符。

Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'.

> org.xml.sax.SAXParseException; systemId: file:/C:/AdroidProjects/RecyclerViewDataBinding/app/build/intermediates/res/merged/debug/layout/activity_main.xml;lineNumber: 8; columnNumber: 45; 与元素类型 "variable" 相关联的 "type" 属性值不能包含 '<' 字符。


错误的写成了:

<variable name="userList" type="List"/>

应该写成:

List<User>"/>

报错3:程序包com.kodulf.recyclerviewdatabinding.databinding不存在


C:\AdroidProjects\RecyclerViewDataBinding\app\src\main\java\com\kodulf\recyclerviewdatabinding\MainActivity.java

Error:(10, 54) 错误: 程序包com.kodulf.recyclerviewdatabinding.databinding不存在

错误: cannot find type argument for User in List

错误: cannot generate view binders java.lang.RuntimeException: failure, see logs for details.

  cannot find type argument for User in List

解决方法,写全路劲

<variable name="userList" type="java.util.List<com.kodulf.recyclerviewdatabinding.User>"/>


报错4: 如果报错是:

Source folders generated at incorrect location

Warning:Folder C:\AdroidProjects\XiMaLaYaTing\app\build\intermediates\dataBindingInfo\debug

Warning:Folder C:\AdroidProjects\XiMaLaYaTing\app\build\intermediates\dataBindingInfo\androidTest\debug

Information:3rd-party Gradle plug-ins may be the cause

那么可以忽略



你可能感兴趣的:(Android,开发点滴,7,Android,Android5.0,新特性)