我在我的 android 应用程序中使用 Guice 依赖注入框架。当我运行我的应用程序时,我得到模块类的 NoClassDefFoundError。
import com.google.inject.AbstractModule;
import com.pps.data.services.UserService;
import com.pps.data.services.IService;
public class DataModule extends AbstractModule{
public void configure ()
{
bind (IService.class).to(UserService.class);
}
}//end dataModule class
public class DataManager {
private static DataManager instance;
private DataModule module;
/*
* Default constructor Singleton Pattern
*/
private DataManager ()
{
module = new DataModule ();
}//end constructor
/**
* Gets instance of DataManager class
* @author Mario Dennis
* @return
*/
public static DataManager getInstance ()
{
if (instance == null)
{
instance = new DataManager ();
return instance;
}
else
return instance;
}//end getInstance method
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> List<T> getAll (Class object)
{
Injector inject = Guice.createInjector(module);
IService<T> service = (IService<T>) inject.getBinding(object.getClass());
return service.getAll();
}
}//end DataManager class
日志猫:
10-21 15:40:54.082: D/dalvikvm(3725): Late-enabling CheckJNI
10-21 15:40:54.902: W/dalvikvm(3725): Unable to resolve superclass of Lcom/pps/data/DataModule; (414)
10-21 15:40:54.902: W/dalvikvm(3725): Link of class 'Lcom/pps/data/DataModule;' failed
10-21 15:40:54.902: E/dalvikvm(3725): Could not find class 'com.pps.data.DataModule', referenced from method com.pps.data.DataManager.<init>
10-21 15:40:54.902: W/dalvikvm(3725): VFY: unable to resolve new-instance 421 (Lcom/pps/data/DataModule;) in Lcom/pps/data/DataManager;
10-21 15:40:54.902: D/dalvikvm(3725): VFY: replacing opcode 0x22 at 0x0003
10-21 15:40:54.902: E/dalvikvm(3725): Could not find class 'com.google.inject.Module[]', referenced from method com.pps.data.DataManager.getAll
10-21 15:40:54.902: W/dalvikvm(3725): VFY: unable to resolve new-array 539 ([Lcom/google/inject/Module;) in Lcom/pps/data/DataManager;
10-21 15:40:54.902: D/dalvikvm(3725): VFY: replacing opcode 0x23 at 0x0001
10-21 15:40:54.902: W/dalvikvm(3725): Unable to resolve superclass of Lcom/pps/data/DataModule; (414)
10-21 15:40:54.902: W/dalvikvm(3725): Link of class 'Lcom/pps/data/DataModule;' failed
10-21 15:40:54.902: D/dalvikvm(3725): DexOpt: unable to opt direct call 0x0bcf at 0x05 in Lcom/pps/data/DataManager;.<init>
10-21 15:40:54.902: D/AndroidRuntime(3725): Shutting down VM
10-21 15:40:54.902: W/dalvikvm(3725): threadid=1: thread exiting with uncaught exception (group=0x40a4e1f8)
10-21 15:40:54.932: E/AndroidRuntime(3725): FATAL EXCEPTION: main
10-21 15:40:54.932: E/AndroidRuntime(3725): java.lang.NoClassDefFoundError: com.pps.data.DataModule
10-21 15:40:54.932: E/AndroidRuntime(3725): at com.pps.data.DataManager.<init>(DataManager.java:17)
10-21 15:40:54.932: E/AndroidRuntime(3725): at com.pps.data.DataManager.getInstance(DataManager.java:31)
10-21 15:40:54.932: E/AndroidRuntime(3725): at com.pps.jamaica.MainActivity.onCreate(MainActivity.java:21)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.Activity.performCreate(Activity.java:4465)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.ActivityThread.access$600(ActivityThread.java:132)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.os.Handler.dispatchMessage(Handler.java:99)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.os.Looper.loop(Looper.java:137)
10-21 15:40:54.932: E/AndroidRuntime(3725): at android.app.ActivityThread.main(ActivityThread.java:4575)
10-21 15:40:54.932: E/AndroidRuntime(3725): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 15:40:54.932: E/AndroidRuntime(3725): at java.lang.reflect.Method.invoke(Method.java:511)
10-21 15:40:54.932: E/AndroidRuntime(3725): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-21 15:40:54.932: E/AndroidRuntime(3725): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-21 15:40:54.932: E/AndroidRuntime(3725): at dalvik.system.NativeStart.main(Native Method)
我该如何解决这个问题,还是我不能使用 Guice 框架来开发 Android 开发?