I was playing with the new data binding library and tried to implement observable interface . But it keeps crashing no matter if i set the age variable to textview or not. The code works fine if i convert age variable to String. Is there any way to make it work with int ?
public class User extends BaseObservable {
@Bindable
public final ObservableField<String> name =
new ObservableField<>();
@Bindable
public final ObservableInt age = new ObservableInt();}
Crash Log :
android.content.res.Resources$NotFoundException: String resource ID #0x3
at android.content.res.Resources.getText(Resources.java:274)
at android.widget.TextView.setText(TextView.java:4122)
at com.hipo.databinding.databinding.ActivityMainBinding.executeBindings(ActivityMainBinding.java:184)
at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:321)
at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:160)
at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:130)
at android.view.View.dispatchAttachedToWindow(View.java:13417)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2707)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2714)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1292)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)public class User extends BaseObservable {
@Bindable
public final ObservableField<String> name =
new ObservableField<>();
@Bindable
public final ObservableInt age = new ObservableInt();
}
Put this in data tag
You need use @{String.valueOf(user.age)} in TextView.
Or @{""+user.age}