为了使我的应用与API 2.2兼容,我添加了Android兼容性库appcompat_v7
&改变了必要的事情。
该应用程序在较新版本中运行良好,但在2.2版本中崩溃。
您可以看到我的 logcat 输出
07-16 14:49:59.551: D/dalvikvm(369): VFY: dead code 0x005e-0061 in Lcom/example/indianconstitution/MainActivity;.displayView (I)V
07-16 14:49:59.870: I/dalvikvm(369): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
07-16 14:49:59.870: W/dalvikvm(369): VFY: unable to resolve virtual method 325: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
07-16 14:49:59.870: D/dalvikvm(369): VFY: replacing opcode 0x6e at 0x008b
07-16 14:49:59.880: I/dalvikvm(369): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
07-16 14:49:59.880: W/dalvikvm(369): VFY: unable to resolve virtual method 321: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
07-16 14:49:59.880: D/dalvikvm(369): VFY: replacing opcode 0x6e at 0x0099
07-16 14:49:59.890: D/dalvikvm(369): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
07-16 14:49:59.890: D/dalvikvm(369): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
07-16 14:50:00.170: I/dalvikvm(369): Could not find method com.example.indianconstitution.MainActivity.invalidateOptionsMenu, referenced from method com.example.indianconstitution.MainActivity$1.onDrawerClosed
07-16 14:50:00.170: W/dalvikvm(369): VFY: unable to resolve virtual method 8573: Lcom/example/indianconstitution/MainActivity;.invalidateOptionsMenu ()V
07-16 14:50:00.170: D/dalvikvm(369): VFY: replacing opcode 0x6e at 0x002d
07-16 14:50:00.180: D/dalvikvm(369): VFY: dead code 0x0030-0030 in Lcom/example/indianconstitution/MainActivity$1;.onDrawerClosed (Landroid/view/View;)V
07-16 14:50:00.180: I/dalvikvm(369): Could not find method com.example.indianconstitution.MainActivity.invalidateOptionsMenu, referenced from method com.example.indianconstitution.MainActivity$1.onDrawerOpened
07-16 14:50:00.180: W/dalvikvm(369): VFY: unable to resolve virtual method 8573: Lcom/example/indianconstitution/MainActivity;.invalidateOptionsMenu ()V
07-16 14:50:00.180: D/dalvikvm(369): VFY: replacing opcode 0x6e at 0x002d
07-16 14:50:00.180: D/dalvikvm(369): VFY: dead code 0x0030-0030 in Lcom/example/indianconstitution/MainActivity$1;.onDrawerOpened (Landroid/view/View;)V
07-16 14:50:00.200: D/AndroidRuntime(369): Shutting down VM
07-16 14:50:00.200: W/dalvikvm(369): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-16 14:50:00.220: E/AndroidRuntime(369): FATAL EXCEPTION: main
07-16 14:50:00.220: E/AndroidRuntime(369): java.lang.NoClassDefFoundError: com.example.indianconstitution.PhotoFragment
07-16 14:50:00.220: E/AndroidRuntime(369): at com.example.indianconstitution.MainActivity.displayView(MainActivity.java:180)
07-16 14:50:00.220: E/AndroidRuntime(369): at com.example.indianconstitution.MainActivity.onCreate(MainActivity.java:135)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.os.Looper.loop(Looper.java:123)
07-16 14:50:00.220: E/AndroidRuntime(369): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-16 14:50:00.220: E/AndroidRuntime(369): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 14:50:00.220: E/AndroidRuntime(369): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 14:50:00.220: E/AndroidRuntime(369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-16 14:50:00.220: E/AndroidRuntime(369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-16 14:50:00.220: E/AndroidRuntime(369): at dalvik.system.NativeStart.main(Native Method)
我尝试了这些问题中提供的所有答案,但没有帮助:
我也尝试添加android-support-v4.jar
,但它与appcompat有冲突,所以我删除了v4 jar。
我现在该怎么办?有什么想法吗?
编辑:这是我在displayView(7)
onCreate
调用PhotoFragment类的方法
@SuppressLint("NewApi")
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new IntroductionFragment();
break;
case 1:
fragment = new PrefaceFragment();
break;
case 2:
fragment = new PreambleFragment();
break;
case 3:
fragment = new ContentsFragment();
break;
case 4:
fragment = new SchedulesFragment();
break;
case 5:
fragment = new AppendixFragment();
break;
case 6:
fragment = new AmendmentFragment();
break;
case 7:
fragment = new PhotoFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
答案 0 :(得分:0)
getFragmentManager仅在API11中添加(http://developer.android.com/reference/android/app/Fragment.html#getFragmentManager())您应该更改代码以使用getSupportFragmentManager()。你可以在这里找到关于android-support-v4.jar的api的更多信息(http://developer.android.com/reference/android/support/v4/app/Fragment.html)。
你需要使用android-support-v4.jar来支持android 2.2中的片段