无法启动活动ComponentInfo android.view.InflateException:二进制XML文件行#27:错误膨胀类片段

时间:2015-02-03 08:39:59

标签: android android-fragments

当我运行YouTube WatchMe android项目时,我得到以下异常:

02-03 14:06:36.865: E/AndroidRuntime(14244): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.apps.watchme/com.google.android.apps.watchme.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class fragment
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread.access$700(ActivityThread.java:150)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.os.Looper.loop(Looper.java:137)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread.main(ActivityThread.java:5283)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at java.lang.reflect.Method.invokeNative(Native Method)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at java.lang.reflect.Method.invoke(Method.java:511)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at dalvik.system.NativeStart.main(Native Method)
02-03 14:06:36.865: E/AndroidRuntime(14244): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class fragment
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:364)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Activity.setContentView(Activity.java:1930)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at com.google.android.apps.watchme.MainActivity.onCreate(MainActivity.java:82)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Activity.performCreate(Activity.java:5283)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
02-03 14:06:36.865: E/AndroidRuntime(14244):    ... 11 more
02-03 14:06:36.865: E/AndroidRuntime(14244): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.apps.watchme.EventsListFragment: make sure class name exists, is public, and has an empty constructor that is public
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Fragment.instantiate(Fragment.java:596)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Fragment.instantiate(Fragment.java:560)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Activity.onCreateView(Activity.java:4864)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
02-03 14:06:36.865: E/AndroidRuntime(14244):    ... 21 more
02-03 14:06:36.865: E/AndroidRuntime(14244): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.apps.watchme.EventsListFragment" on path: /data/app/com.google.android.apps.watchme-1.apk
02-03 14:06:36.865: E/AndroidRuntime(14244):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-03 14:06:36.865: E/AndroidRuntime(14244):    at android.app.Fragment.instantiate(Fragment.java:582)
02-03 14:06:36.865: E/AndroidRuntime(14244):    ... 24 more

代码:

public class MainActivity extends Activity implements
    EventsListFragment.Callbacks {

private EventsListFragment mEventsListFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mEventsListFragment = (EventsListFragment) getFragmentManager()
            .findFragmentById(R.id.list_fragment);

   }
}

我检查了我的包裹名称xmls的所有内容,但我不知道为什么我会收到这个。

2 个答案:

答案 0 :(得分:0)

  1. 检查EventsListFragment是否公开
  2. 您正在传递的布局文件(activity_main)中的
  3. com.google.android.apps.watchme.EventsListFragment作为片段的地址 ,检查EventsListFragment的地址是否正确

答案 1 :(得分:0)

添加android-support-v4.jar解决了我的问题。此外,将优先级更改为top&在项目属性部分检查它。