问题现象:进入应用程序后马上就退出,有些手机是正常的,有些手机不正常
Log:
01-01 08:08:53.029 1260 1260 W dalvikvm: Link of class 'Lcom/shopping/test/ui/CategoryActivity;' failed
01-01 08:08:53.029 1260 1260 E dalvikvm: Could not find class 'com.shopping.test.ui.CategoryActivity', referenced from method com.shopping.test.ui.HomeActivity.c
01-01 08:08:53.029 1260 1260 W dalvikvm: VFY: unable to resolve const-class 1058 (Lcom/shopping/test/ui/CategoryActivity;) in Lcom/shopping/test/ui/HomeActivity;
01-01 08:08:53.129 1260 1260 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40150560)
01-01 08:08:53.139 1260 1260 E AndroidRuntime: FATAL EXCEPTION: main
01-01 08:08:53.139 1260 1260 E AndroidRuntime: java.lang.NoClassDefFoundError: com.shopping.test.ui.CategoryActivity
01-01 08:08:53.139 1260 1260 E AndroidRuntime: at com.shopping.test.ui.HomeActivity.c(Unknown Source)
01-01 08:08:53.139 1260 1260 E AndroidRuntime: at com.shopping.test.ui.HomeActivity.onCreate(Unknown Source)
01-01 08:08:53.139 1260 1260 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
根据log知道原因是找不到CategoryActivity这个类,但是有些手机是正常的(后面发现是Android 2.3版本系统都有问题),初步推断是兼容性问题,那么哪里不兼容呢?
一开始以为是jar加载方式不对,在stack overflow也能看到有类似问题,解决方法是通过合理引入jar,但是不适合我这种情况。
于是检查自己的代码,逐步排除,最后锁定到是LoaderCallbacks这个接口的兼容性问题,要使用android.support.v4.*下对应的包就可以解决。