我正在尝试为任何Android视图创建自定义属性.
我在this post中看到我可以使用数据绑定库来完成它. Data Binding Guide和帖子解释布局应该以< layout>开头.标签,但在膨胀时,我得到以下异常:
05-06 22:36:31.294 11916-11916/com.plnech.example E/AndroIDRuntime: FATAL EXCEPTION: mainProcess: com.plnech.example, PID: 11916androID.vIEw.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class layoutat androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:423)at androID.Widget.ArrayAdapter.createVIEwFromresource(ArrayAdapter.java:378)at androID.Widget.ArrayAdapter.getVIEw(ArrayAdapter.java:369)at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:2346)at androID.Widget.ListVIEw.measureHeightOfChildren(ListVIEw.java:1280)at androID.Widget.ListVIEw.onMeasure(ListVIEw.java:1188)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.Widget.relativeLayout.measureChild(relativeLayout.java:676)at androID.Widget.relativeLayout.onMeasure(relativeLayout.java:479)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951)at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)at androID.support.v7.Widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951)at androID.support.v7.Widget.ActionbarOverlayLayout.onMeasure(ActionbarOverlayLayout.java:391)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951)at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951)at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:at androID.Widget.linearLayout.measureVertical(linearLayout.java:748)at androID.Widget.linearLayout.onMeasure(linearLayout.java:630)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951)at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194)at com.androID.internal.policy.PhoneWindow$DecorVIEw.onMeasure(PhoneWindow.java:2643)at androID.vIEw.VIEw.measure(VIEw.java:18788)at androID.vIEw.VIEwRootImpl.performMeasure(VIEwRootImpl.java:2100)at androID.vIEw.VIEwRootImpl.measureHIErarchy(VIEwRootImpl.java:1216)at androID.vIEw.VIEwRootImpl.performTraversals(VIEwRootImpl.java:1452)at androID.vIEw.VIEwRootImpl.doTraversal(VIEwRootImpl.java:1107)at androID.vIEw.VIEwRootImpl$TraversalRunnable.run(VIEwRootImpl.java:6013)at androID.vIEw.Choreographer$CallbackRecord.run(Choreographer.java:858)at androID.vIEw.Choreographer.doCallbacks(Choreographer.java:670)at androID.vIEw.Choreographer.doFrame(Choreographer.java:606)at androID.vIEw.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:44)at androID.os.Handler.handleCallback(Handler.java:739)at androID.os.Handler.dispatchMessage(Handler.java:95)at androID.os.Looper.loop(Looper.java:148)at androID.app.ActivityThread.main(ActivityThread.java:5417)at java.lang.reflect.Method.invoke(Native Method)at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:616)Caused by: androID.vIEw.InflateException: Binary XML file line #1: Error inflating class layoutat androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:776)at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:704)at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:492)at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:423) at androID.Widget.ArrayAdapter.createVIEwFromresource(ArrayAdapter.java:378) at androID.Widget.ArrayAdapter.getVIEw(ArrayAdapter.java:369) at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:2346) at androID.Widget.ListVIEw.measureHeightOfChildren(ListVIEw.java:1280) at androID.Widget.ListVIEw.onMeasure(ListVIEw.java:1188) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.Widget.relativeLayout.measureChild(relativeLayout.java:676) at androID.Widget.relativeLayout.onMeasure(relativeLayout.java:479) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951) at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194) at androID.support.v7.Widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951) at androID.support.v7.Widget.ActionbarOverlayLayout.onMeasure(ActionbarOverlayLayout.java:391) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951) at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951) at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1465)at androID.Widget.linearLayout.measureVertical(linearLayout.java:748) at androID.Widget.linearLayout.onMeasure(linearLayout.java:630) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:5951) at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:194) at com.androID.internal.policy.PhoneWindow$DecorVIEw.onMeasure(PhoneWindow.java:2643) at androID.vIEw.VIEw.measure(VIEw.java:18788) at androID.vIEw.VIEwRootImpl.performMeasure(VIEwRootImpl.java:2100) at androID.vIEw.VIEwRootImpl.measureHIErarchy(VIEwRootImpl.java:1216) at androID.vIEw.VIEwRootImpl.performTraversals(VIEwRootImpl.java:1452) at androID.vIEw.VIEwRootImpl.doTraversal(VIEwRootImpl.java:1107) at androID.vIEw.VIEwRootImpl$TraversalRunnable.run(VIEwRootImpl.java:6013) at androID.vIEw.Choreographer$CallbackRecord.run(Choreographer.java:858) at androID.vIEw.Choreographer.doCallbacks(Choreographer.java:670) at androID.vIEw.Choreographer.doFrame(Choreographer.java:606) at androID.vIEw.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:844)at androID.os.Handler.handleCallback(Handler.java:739) at androID.os.Handler.dispatchMessage(Handler.java:95) at androID.os.Looper.loop(Looper.java:148) at androID.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.classNotFoundException: DIDnt find class "androID.vIEw.layout" on path: DexPathList[[zip file "/data/app/com.plnech.example-2/base.apk"],nativelibraryDirectorIEs=[/data/app/com.plnech.example-2/lib/x86, /vendor/lib, /system/lib]]at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)at java.lang.classLoader.loadClass(ClassLoader.java:511)at java.lang.classLoader.loadClass(ClassLoader.java:469)at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:583)
这是有问题的布局:
<?xml version="1.0" enCoding="utf-8"?><layout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:app="http://schemas.androID.com/tools"> <linearLayout androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content"> <TextVIEw androID:ID="@androID:ID/text1" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" app:attribute="name"/> </linearLayout></layout>
这是我的build.gradle的相关部分:
buildscript { repositorIEs { jcenter() } dependencIEs { classpath 'com.androID.tools.build:gradle:2.1.0' classpath 'com.androID.databinding:dataBinder:1.0-rc4' }}...androID { dataBinding { enabled true }}...
为什么这种布局在充气时会导致错误?
解决方法:
您需要包含< data>你的< layout>里面:
<layout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/tools"> <data> </data> <linearLayout androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content"> <TextVIEw androID:ID="@androID:ID/text1" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" app:attribute="name"/> </linearLayout></layout>
另外,如果您使用的是gradle版本2,则不再需要类路径’com.androID.databinding:dataBinder:1.0-rc4’和apply plugin:’com.androID.databinding’.
总结以上是内存溢出为你收集整理的android – 为什么在ClassNotFound异常中使用绑定接口重新启动?全部内容,希望文章能够帮你解决android – 为什么在ClassNotFound异常中使用绑定接口重新启动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)