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区别
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。