我的应用程序在Android 4.0+上工作正常,但是当我尝试在ver上启动时出现错误。 2.3 有什么建议? 机器人:的minSdkVersion = “8” 机器人:targetSdkVersion = “15”
09-16 21:37:29.759:E / AndroidRuntime(8307):致命异常:主
09-16 21:37:29.759:E / AndroidRuntime(8307): java.lang.RuntimeException:无法启动活动 ComponentInfo {com.example.Catholic_app / com.example.Catholic_app.News.Top}: android.view.InflateException:二进制XML文件行#2:错误 膨胀类片段
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread.access $ 1500(ActivityThread.java:121)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:943)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.os.Looper.loop(Looper.java:130)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread.main(ActivityThread.java:3701)
09-16 21:37:29.759:E / AndroidRuntime(8307):at java.lang.reflect.Method.invokeNative(Native Method)
09-16 21:37:29.759:E / AndroidRuntime(8307):at java.lang.reflect.Method.invoke(Method.java:507)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
09-16 21:37:29.759:E / AndroidRuntime(8307):at dalvik.system.NativeStart.main(原生方法)
09-16 21:37:29.759:E / AndroidRuntime(8307):引起: android.view.InflateException:二进制XML文件行#2:错误 膨胀类片段
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.setMenu(SlidingMenu.java:375)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.example.Catholic_app.News.Top.createSlidingMenu(Top.java:81)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.example.Catholic_app.News.Top.onCreate(Top.java:70)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
09-16 21:37:29.759:E / AndroidRuntime(8307):... 11更多
09-16 21:37:29.759:E / AndroidRuntime(8307):引起: java.lang.ClassNotFoundException:loader中的android.view.fragment dalvik.system.PathClassLoader [/data/app/com.example.Catholic_app-1.apk]
09-16 21:37:29.759:E / AndroidRuntime(8307):at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-16 21:37:29.759:E / AndroidRuntime(8307):at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-16 21:37:29.759:E / AndroidRuntime(8307):at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.createView(LayoutInflater.java:471)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
09-16 21:37:29.759:E / AndroidRuntime(8307):at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
09-16 21:37:29.759:E / AndroidRuntime(8307):at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
09-16 21:37:29.759:E / AndroidRuntime(8307):... 19更多
我的代码中没有使用getSupportFragmentManager()或getFragmentManager()方法。 我使用添加lib“滑动菜单”。 Erorr在这段代码中出现了
slidingMenu.setMenu(R.layout.slidingmenu);
我称之为slidemenu库的下一个方法
public void setMenu(int res) {
setMenu(LayoutInflater.from(getContext()).inflate(res, null));
}
我的 R.layout.slidingmenu 文件
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="schemas.android.com/apk/res/android"
android:name="com.example.Catholic_app.Menu.SlidingMenuFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slidingmenu"> </fragment>
P.S。 support-library-v4已经添加
答案 0 :(得分:2)
要使用版本3.0下方的Fragment
,您必须在应用程序中使用其支持库。
您应该使用getSupportFragmentManager()
代替getFragmentManager()
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
有关详细信息,请查看HERE
要将其中一个库添加到Android项目中:
In your Android project, create a directory named libs at the root of your project (next to src/, res/, etc.)
Locate the JAR file for the library you want to use and copy it into the libs/ directory.
For example, the library that supports API level 4 and up is located at <sdk>/extras/android/support/v4/android-support-v4.jar.
Add the JAR to your project build path.
答案 1 :(得分:0)
当您创建Android应用时,您设置minimum sdk version
,target sdk
和compile with
就像图片一样检查它!