我正在关注以下链接以在 anadroid 中创建片段
http://www.vogella.com/articles/Android/article.html#fragments
但它总是给出classnotfound异常。请指导我如何解决它?
日志猫:
07-25 14:45:22.511: E/AndroidRuntime(497): FATAL EXCEPTION: main
07-25 14:45:22.511: E/AndroidRuntime(497): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragment/com.example.fragment.FragmentProjectActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.os.Looper.loop(Looper.java:123)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 14:45:22.511: E/AndroidRuntime(497): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 14:45:22.511: E/AndroidRuntime(497): at java.lang.reflect.Method.invoke(Method.java:521)
07-25 14:45:22.511: E/AndroidRuntime(497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 14:45:22.511: E/AndroidRuntime(497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 14:45:22.511: E/AndroidRuntime(497): at dalvik.system.NativeStart.main(Native Method)
07-25 14:45:22.511: E/AndroidRuntime(497): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-25 14:45:22.511: E/AndroidRuntime(497): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.Activity.setContentView(Activity.java:1647)
07-25 14:45:22.511: E/AndroidRuntime(497): at com.example.fragment.FragmentProjectActivity.onCreate(FragmentProjectActivity.java:11)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-25 14:45:22.511: E/AndroidRuntime(497): ... 11 more
07-25 14:45:22.511: E/AndroidRuntime(497): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.fragment-2.apk]
07-25 14:45:22.511: E/AndroidRuntime(497): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-25 14:45:22.511: E/AndroidRuntime(497): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-25 14:45:22.511: E/AndroidRuntime(497): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
07-25 14:45:22.511: E/AndroidRuntime(497): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-25 14:45:22.511: E/AndroidRuntime(497): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
07-25 14:45:22.511: E/AndroidRuntime(497): ... 20 more