Dagger模块抛出NoSuchMethodException

时间:2019-06-30 21:11:48

标签: dagger

我是匕首DI框架的新手。因此,我有一个名为“ ServiceLambdaRouter”的类,该类取决于类“ Activity”。我在模块中提供了Activity实例,并试图使用字段注入将其注入。但是,当我尝试运行代码时,出现了NoSuchMethodFound异常。

我曾尝试在google上找到有关此问题的可能解释,但没有做任何事情。

我的路由器类:

public class ServiceLambdaRouter extends LambdaRouter {

    private ServiceComponent serviceComponent;


    @Inject
    @Named(value = ServiceAdapterModule.ACTIVITY) Activity Activity;


    /**
     * Constructor with arguments.
     */
    @Inject public ServiceLambdaRouter() {

    }


    @VisibleForTesting
    void setServiceComponent(ServiceComponent serviceComponent) {
        this.serviceComponent = serviceComponent;
    }

    private ServiceComponent getServiceComponent() {
        if (Objects.isNull(serviceComponent)) {
            serviceComponent = DaggerServiceComponent.create();
            serviceComponent.inject(this);
        }
        return serviceComponent;
    }
}

这是我的serviceComponent接口:

@Singleton
@Component(modules = {MetricsModule.class, ServiceAdapterModule.class, AppConfigModule.class})
public interface ServiceComponent {
    MetricsHandler metricsHandler();

    void inject(ServiceLambdaRouter serviceLambdaRouter);
}

这是我提供了Activity实例的serviceAdapterModule类:

@Module
public class ServiceAdapterModule {

    public static final String RISK_STATUS_ACTIVITY = "Activity";


    @Provides
    @Singleton
    public Client getClient() {
        return ClientFactory
                .getInstance()
                .newCloudAuthEnabledInstance(4000, 1000);
    }

    @Provides
    @Singleton
    @Named(value = ACTIVITY )
    public Activity getActivity() {
        return new Activity();
    }
}

当我尝试测试此代码时,出现以下错误。

java.lang.NoSuchMethodError: com.servicelambda.dagger.ServiceAdapterModule_GetActivityFactory.create(Lcom/amazon/servicelambda/dagger/ServiceAdapterModule;Ljavax/inject/Provider;)Ldagger/internal/Factory;
        at com.sellertrustdiscoveryservicelambda.dagger.DaggerServiceComponent.initialize(DaggerServiceComponent.java:64)
        at com.servicelambda.dagger.DaggerServiceComponent.<init>(DaggerServiceComponent.java:34)
        at com.servicelambda.dagger.DaggerServiceComponent.<init>(DaggerServiceComponent.java:20)
        at com.servicelambda.dagger.DaggerServiceComponent$Builder.build(DaggerServiceComponent.java:101)
        at com.servicelambda.dagger.DaggerServiceComponent.create(DaggerServiceComponent.java:42)
        at com.servicelambda.activity.ServiceLambdaRouter.getServiceComponent(ServiceLambdaRouter.java:86)
        at com.sellertrustdiscoveryservicelambda.activity.SellerTrustDiscoveryServiceLambdaRouter.initialize(ServiceLambdaRouter.java:61)
        at com.bones.lambdarouter.LambdaEntryPoint.oneTimeInit(LambdaEntryPoint.java:32)
        at com.bones.lambdarouter.LambdaEntryPoint.<init>(LambdaEntryPoint.java:23)
        at com.servicelambda.activity.serviceLambdaEntryPoint.<init>(serviceLambdaEntryPoint.java:11)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

0 个答案:

没有答案