我正在学习如何使用片段..我遇到了这个错误,并且无法纠正它...尝试了很多组合..我尝试在网上搜索这个...可以& #39;解决它仍然.. ..
当我复制这个完整的项目时,在我的旧项目中使用片段..它完全正常,没有任何错误.. 我认为支持库有一些错误,所以我删除并再次添加了库,这在WORKING PROJECT中没有任何问题但是没有成功.. 感谢。
11-03 08:22:47.336: E/AndroidRuntime(1608): FATAL EXCEPTION: main
11-03 08:22:47.336: E/AndroidRuntime(1608): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragrevb/com.example.fragrevb.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread.access$600(ActivityThread.java:122)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.os.Looper.loop(Looper.java:137)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread.main(ActivityThread.java:4340)
11-03 08:22:47.336: E/AndroidRuntime(1608): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 08:22:47.336: E/AndroidRuntime(1608): at java.lang.reflect.Method.invoke(Method.java:511)
11-03 08:22:47.336: E/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-03 08:22:47.336: E/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-03 08:22:47.336: E/AndroidRuntime(1608): at dalvik.system.NativeStart.main(Native Method)
11-03 08:22:47.336: E/AndroidRuntime(1608): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
11-03 08:22:47.336: E/AndroidRuntime(1608): at com.example.fragrevb.MainActivity.onCreate(MainActivity.java:15)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Activity.performCreate(Activity.java:4465)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
11-03 08:22:47.336: E/AndroidRuntime(1608): ... 11 more
11-03 08:22:47.336: E/AndroidRuntime(1608): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.fragreva.FragA: make sure class name exists, is public, and has an empty constructor that is public
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Fragment.instantiate(Fragment.java:572)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Fragment.instantiate(Fragment.java:540)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Activity.onCreateView(Activity.java:4235)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
11-03 08:22:47.336: E/AndroidRuntime(1608): ... 21 more
11-03 08:22:47.336: E/AndroidRuntime(1608): Caused by: java.lang.ClassNotFoundException: com.example.fragreva.FragA
11-03 08:22:47.336: E/AndroidRuntime(1608): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-03 08:22:47.336: E/AndroidRuntime(1608): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-03 08:22:47.336: E/AndroidRuntime(1608): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-03 08:22:47.336: E/AndroidRuntime(1608): at android.app.Fragment.instantiate(Fragment.java:562)
11-03 08:22:47.336: E/AndroidRuntime(1608): ... 24 more
<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.fragrevb.MainActivity"
android:background="#00BBFF">
<fragment
android:id="@+id/fragment1"
android:name="com.example.fragrevb.FragA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/fragment2"
android:name="com.example.fragrevb.FragB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/fragment1"
android:layout_below="@+id/fragment1"
android:layout_marginTop="38dp" />
这是代码..我已经纠正了错误。这是我的坏事。 在activity_main.xml中添加片段时,我已经在另一个项目中创建了2个具有相同名称的片段。所以我在这个活动(当前项目)中添加了这些片段(来自其他项目)..之前, android:name =&#34; com.example.fragreva.FragB&#34; 和 android:name =&#34; com.example.fragreva.FragA&#34; (这是错的)..我把它改为 android:name =&#34; com.example.fragrevb.FragB&#34; 和 android:name =&#34; com .example.fragrevb.FragA&#34; ..因为错误..课程倾斜。谢谢大家试图帮忙!欢呼声。