在练习数据绑定时,出现以下错误
FATAL EXCEPTION: main
Process: com.vogella.android.databinding, PID: 8332 android.content.res.Resources$NotFoundException: String resource ID #0x11 at android.content.res.Resources.getText(Resources.java:347) at android.content.res.MiuiResources.getText(MiuiResources.java:97) at android.widget.TextView.setText(TextView.java:4557) at com.vogella.android.databinding.databinding.ActivityMainBinding.executeBindings(ActivityMainBinding.java:170) 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:15412) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2953) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2960) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1561) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1291) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6362) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873) at android.view.Choreographer.doCallbacks(Choreographer.java:685) at android.view.Choreographer.doFrame(Choreographer.java:621) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859) at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:160) at android.app.ActivityThread.main(ActivityThread.java:6200) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
原因是由于数据绑定不能找到 Int类型的值。
解决办法把@{people.age}改为@{
String.valueOf(people.age)}.