首页 > 代码库 > Android - Binary XML file line #8: Error inflating class fragment
Android - Binary XML file line #8: Error inflating class fragment
Error:
threadid=1: thread exiting with uncaught exception (group=0x415c5940) FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wifidirectdemo/com.example.wifidirectdemo.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2282) at android.app.ActivityThread.access$600(ActivityThread.java:147) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5265) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:760) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267) at android.app.Activity.setContentView(Activity.java:1901) at com.example.wifidirectdemo.MainActivity.onCreate(MainActivity.java:39) at android.app.Activity.performCreate(Activity.java:5146) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2191) ... 11 more Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.news.ArticleListFragment: make sure class name exists, is public, and has an empty constructor that is public at android.app.Fragment.instantiate(Fragment.java:602) at android.app.Fragment.instantiate(Fragment.java:566) at android.app.Activity.onCreateView(Activity.java:4751) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689) ... 21 more Caused by: java.lang.ClassNotFoundException: Didn‘t find class "com.example.news.ArticleListFragment" on path: DexPathList[[zip file "/data/app/com.example.wifidirectdemo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wifidirectdemo-1, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53) at java.lang.ClassLoader.loadClass(ClassLoader.java:501) at java.lang.ClassLoader.loadClass(ClassLoader.java:461) at android.app.Fragment.instantiate(Fragment.java:588) ... 24 more
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wifidirectdemo/com.example.wifidirectdemo.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.news.ArticleListFragment: make sure class name exists, is public, and has an empty constructor that is public
istFragment" on path: DexPathList[[zip file "/data/app/com.example.wifidirectdemo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wifidirectdemo-1, /vendor/lib, /system/lib]]
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.wifidirectdemo.MainActivity" > <fragment android:name="com.example.news.ArticleListFragment" android:id="@+id/frag_list" android:layout_width="0dp" android:layout_height="match_parent" /> <fragment android:name="com.example.news.ArticleReaderFragment" android:id="@+id/frag_detail" android:layout_width="0dp" android:layout_height="match_parent" /> </RelativeLayout>
出错: com.example.news.ArticleReaderFragment
正确的fragment处理类和路径为:
根据网络上一些解决方案,无需将 android.app.Fragment 替换为 android.support.v4.app.Fragment
参考链接:android.support.v4.app.Fragment和android.app.Fragment区别
本文出自 “飒飒秋风” 博客,请务必保留此出处http://xjhznick.blog.51cto.com/3608584/1556638
Android - Binary XML file line #8: Error inflating class fragment
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。