When trying to add data binding to my app, I see a crash after a ClassCastException
inside MainActivityBinding
. Here is the stack trace:
com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 15524
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.CharSequence
at com.mayapp.databinding.MainActivityBinding.executeBindings(MainActivityBinding.java:553)
at android.databinding.ViewDataBinding.executeBindingsInternal(ViewDataBinding.java:379)
at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:351)
at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:178)
at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:146)
at android.view.View.dispatchAttachedToWindow(View.java:17392)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3319)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3326)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3326)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3326)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1658)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Inside main_activity.xml
I have the following:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="tiles"
type="com.myapp.Tile[]" />
</data>
...
Tile[]
is underlined giving me the "Cannot resolve symbol ..." error which I chose to ignore since the docs say:
Note: Arrays and a generic type, such as the Observable class, might display errors when there are no errors.
The gradle build is successful, however, when I run the app on an emulator or on a physical device I get the above error.
When I follow the link from the stack trace I can actually enter MainActivityBinding
. Among a lot of code I find the following method marked by the compiler:
public boolean setVariable(int variableId, Object variable) {
switch(variableId) {
case BR.tiles :
setTiles((com.myapp.Tile[]) variable);
return true;
}
return false;
}
BR.tiles
is underlined and the compiler tells me: "Constant expression required".
Is this a bug or am I doing something wrong?