I am using Android Studio for my Android projects. I faced an issue when builds crash with strange stacktrace, like this:
Error:Execution failed for task ':app:compileDevDebugJavaWithJavac'.
java.lang.RuntimeException: failure, see logs for details.
cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.reflection.ModelMethod.isBoxingConversion(ModelMethod.java:155)
at android.databinding.tool.store.SetterStore.isBetterParameter(SetterStore.java:946)
at android.databinding.tool.store.SetterStore.getBestSetter(SetterStore.java:838)
and it was seemed that the databinding became broken as whole.
I made refactoring before and moved classes between packages.
In my case, I relied on Android Studio when renaming and moving classes between packages. But it didn't proceed correction for XMLs of layouts where were references on refactored classes in the type attribute of variable element in data.
So my previous type's value pointed to non existing files and build crashed.
It's simple mistake but it may take more time to find the source. Hope this would help someone.
For me, this started happening after updating Android Studio to version 3.5.2
To fix it, I downgraded Android Gradle Plugin
buildscript {
repositories {
//..........
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
//......
}
}
Make sure you import all classes you reference in xml bindings
I had code something like:
android:visible="#{obj instanceof A}"
I was getting that same error.
Turns out that class A was not imported on top. Adding <import type="com.company.A"> tag resolved the problem.
P.S. android:visible is a custom binding adapter I have.
If this question is still relevant. For me I figured that in my xml layout file I was including a class (not an instance of one) as a variable, i.e I had this code
<variable
name="Converters"
type="com.example.flexapp.utils.Converters" />
and it should have been
<import type="com.example.flexapp.utils.Converters"/>
since this was a class and not an object.
in my case my problem was in a LongClickListener that the method for this listener must have returned a boolean but my method returned void so when I added the correct return statement it worked just fine.
keep in mind if you use a data binding method you must return the correct value or else the error it throws is not helpful at all.
You may have stumbled upon this question after migrating to Android X. If that's the case, and you're positive your XML files are okay, but it's still not working, you should start looking at libraries that generate code.
Libraries that generate code cannot be easily converted by the Jettifyer. Some info here - https://blog.danlew.net/2018/11/14/the-reality-of-migrating-to-androidx/
In my case, I updated the obvious ones, but I still was missing something. So, what I did was go into my develop branch (that wasn't Android X), ran a build, and dug into the build folder to see all of the libraries that generated code. Once I did that, I was able to look at the suspects one by one until I found the dependency that was causing this issue. You could either update it, or, in my case, remove it, and this error was resolved. :)
The getter function for any instance that you refer from your xml file might not have been defined or the getter function might not have public access specifier.
Downgrading Android Gradle Plugin to 3.5.1 fixed the issue for me
I face this problem when I define variable like this (Android Studio don't warning anything)
<data>
<variable
name="onGlobalLayoutA"
type="ViewTreeObserver.OnGlobalLayoutListener"/>
<import type="android.view.ViewTreeObserver"/>
</data>
And I solve it by
<data>
<variable
name="onGlobalLayoutA"
type="android.view.ViewTreeObserver.OnGlobalLayoutListener"/>
</data>
Hope this would help someone.
In my case, the reason was that I used a type for a variable which is another module and that module is added as 'implementation ' in build script. Changing to 'api ' resolved the issue.
Clearly not the same issue as the one posted by atlascoder but I mention regardless, maybe someone gits this article with the same problem as I had.
As #hiddeneyes02 mentioned, this started happen when upgrading from Android Gradle Plugin from 3.5.1 to 3.5.2, this seems to be the bug:
https://issuetracker.google.com/issues/143778134
When I built the project with the command tool I got the same errors as in this post:
When building Android project with Android Gradle Plugin v. 3.5.2 my builds fail
In my case I wrote wrong the name of my view model variable inside the XML file. I had it named VProgressBar instead of vProgressBar:
android:visibility="#{fatherViewModel.vProgressBar}"
One screenshot is one thousand words:
What Am I doing so wrong guys? Is it my face it does not like?
Updates....
When I tried a new project with both "Target SDK" and "Compile With:" set to "API 23: Android 6.0" the Problem Errors disappeared but I get errors in the Console tab like this:
You are using ActionBarActivity, and you didn't included it.
But, ActionBarActivity was deprecated, because Toolbar was introduced.
See this:
Why was ActionBarActivity deprecated
If you still want to use ActionBarActivity for study, See this to add appcompat7: https://stackoverflow.com/a/20523124/850347
Import appcompat library and clean and rebuild the project.
I use Gradle to add the dependency org.roboguice:roboguice:3.0b-experimental to my project.
I found a post on the issue tracker, saying that there should be a RoboActionBarActivity class (to replace the ActionBarActivity I use for drawer navigation) in the latest beta. I can find the code on Github, but the class isn't in the jar. I found several implementations of the RoboActionBarActivity on the web, but those have other dependencies, and I don't want to resolve them all manually. Is there a way to get this class via Gradle?
Until the RoboActionBarActivity class is provided with the RoboGuice library you can make your own descendant class for ActionBar support. Or you can get the ActionBar4RoboGuice library, which contains the original RoboActionBarActivity, and use it with the latest stable release of RoboGuice.
I am trying to implement the SlidingMenu from https://github.com/jfeinstein10/SlidingMenu together with http://actionbarsherlock.com/ and I came across a problem that I could not fix myself that's why I turned to the issues page on SlidingMenu's GitHub. But 2 days and I got no reply so I am gonna ask it here.
Basically on the example project provided by jfeinstein10, I copied the SampleListFragment.java file and I've named it MenuListFragment.java on my project. I've made a couple of changes but those should not be an issue.
I also copied the menu.xml from the layout directory but changed its name attribute to the previous file including the package.
Project builds properly and no errors are encountered. Time to run the project.
Now on my project's main activity, when I call the setMenu(R.layout.menu); statement during runtime, it gives me an error which tells me something about ClassCastException (cannot cast com.dokgu.dota2stats.MenuListFragment to android.app.Fragment).
I've tried a couple of things like change the MenuListFragment.java to extend the android.app.Fragment instead of ListFragment but it didn't solve the problem and more issues came up because of that.
So please, can anyone help me with this please? I really want to make this work.
You can find the issue here as well: https://github.com/jfeinstein10/SlidingMenu/issues/546
Actionbarsherlork supports the lower lever version since android 2.x while the slidingmenu needs android 3.0+.Maybe you can add the android-support-v4.jar ,with some fragment and activity in slidingmenu project extending to.
For some reason I cannot see the line of code:
session = new Session.OpenRequest(this).setCallBack(statusCallBack)
It gives me an error that Session.OpenRequest(myFragment) is undefined. Does anyone know why this is and how I can fix it?
Found out what i was doing wrong. It has to be a fragment from the support library. I was extending the regular fragment class.
Apparently, Session.OpenRequest(Fragment fragment) constructor should work. Assuming that you have added Facebook SDK properly in your project, organize the imports in your class to import the Session.OpenRequest class. This constructor seems to be invisible for your code.
If you are using Eclipse IDE organize imports by pressing Ctrl+Shift+O.