导致“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
答案 0 :(得分:0)
这是由布局文件中的错误或布局文件中使用的片段或组件中的错误引起的。由于在编辑时检测到xml中的错误,因此您可能在片段中创建了一个错误(如NullPointerException),或者您创建了在布局中使用的视图。 但是你不能指望人们正确地回答你的问题,如果你给我们的只是你的logcat中的一行。发布整个堆栈跟踪,然后有人可以指出你的代码中有什么问题。如果可能,请发布相关的代码位,例如项目中生成堆栈跟踪的类。