-2

导致“android.view.ViewInflate$InflateException: Binary xml file”的可能原因是什么?以下是所有错误。我不知道为什么,每次我创建一些关于 Fragments 的项目时,它都会提示这些错误。

09-21 22:57:09.166: E/AndroidRuntime(674): FATAL EXCEPTION: main
09-21 22:57:09.166: E/AndroidRuntime(674): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testfra/com.example.testfra.FragTestActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class Fragment
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.os.Looper.loop(Looper.java:137)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread.main(ActivityThread.java:4424)
09-21 22:57:09.166: E/AndroidRuntime(674):  at java.lang.reflect.Method.invokeNative(Native Method)
09-21 22:57:09.166: E/AndroidRuntime(674):  at java.lang.reflect.Method.invoke(Method.java:511)
09-21 22:57:09.166: E/AndroidRuntime(674):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-21 22:57:09.166: E/AndroidRuntime(674):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-21 22:57:09.166: E/AndroidRuntime(674):  at dalvik.system.NativeStart.main(Native Method)
09-21 22:57:09.166: E/AndroidRuntime(674): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class Fragment
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-21 22:57:09.166: E/AndroidRuntime(674):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.Activity.setContentView(Activity.java:1835)
09-21 22:57:09.166: E/AndroidRuntime(674):  at com.example.testfra.FragTestActivity.onCreate(FragTestActivity.java:12)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.Activity.performCreate(Activity.java:4465)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-21 22:57:09.166: E/AndroidRuntime(674):  ... 11 more
09-21 22:57:09.166: E/AndroidRuntime(674): Caused by: java.lang.ClassNotFoundException: android.view.Fragment
09-21 22:57:09.166: E/AndroidRuntime(674):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-21 22:57:09.166: E/AndroidRuntime(674):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-21 22:57:09.166: E/AndroidRuntime(674):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
09-21 22:57:09.166: E/AndroidRuntime(674):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
09-21 22:57:09.166: E/AndroidRuntime(674):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
09-21 22:57:09.166: E/AndroidRuntime(674):  ... 21 more
4

1 回答 1

0

这是由布局文件或布局文件中使用的片段或组件中的错误引起的。由于在编辑时检测到 xml 中的错误,您很可能会在您创建的用于布局的片段或视图中遇到错误(如 NullPointerException)。但是你不能指望人们正确回答你的问题,如果你给我们的只是你的 logcat 中的一行。发布整个堆栈跟踪,然后有人可能会向您指出您的代码中有什么问题。如果可能,请发布相关的代码,例如项目中生成堆栈跟踪的类。

于 2012-09-21T23:48:22.683 回答