无法创建类ViewModel dagger2

时间:2018-10-21 20:02:07

标签: java android kotlin dagger

无法创建类FacebookViewMdel的实例。 dispatchingAndroidInjector和viewModelFactory返回nullObject引用。 试图使用匕首制作Facebook ligin页面。

    public class FacebookActivity extends AppCompatActivity implements IOnRequestCompleted,
        RestFinishLoginWithFbInterface,HasActivityInjector,RestPostAllContactInterface {

    @Inject
    DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

    @Inject
    ViewModelProvider.Factory viewModelFactory;

    private FacebookViewModel viewModel;



     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_facebook);
        ButterKnife.bind(this);

       viewModel=ViewModelProviders.of(FacebookActivity.this,viewModelFactory).get(FacebookViewModel.class);


FacebookViewModel.class

    class FacebookViewModel
@Inject constructor(
        application: Application,
         val appRepository: AppRepository
) : AndroidViewModel(application) {

    fun signInWithCustomToken(token: String): Completable =
            appRepository.signInWithCustomToken(token)

    fun setCurrentUser(user: User) {
        appRepository.setCurrentUser(user)
    }
}
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.miracas.groupgiri/com.miracas.groupgiri.ui.facebook.FacebookActivity}:
     

java.lang.RuntimeException:无法创建类的实例   com.miracas.groupgiri.ui.facebook.FacebookViewModel           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2792)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)           在android.app.ActivityThread.-wrap11(未知来源:0)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1601)           在android.os.Handler.dispatchMessage(Handler.java:106)           在android.os.Looper.loop(Looper.java:172)           在android.app.ActivityThread.main(ActivityThread.java:6590)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)        原因:java.lang.RuntimeException:无法创建com.miracas.groupgiri.ui.facebook.FacebookViewModel类的实例           在android.arch.lifecycle.ViewModelProvider $ AndroidViewModelFactory.create(ViewModelProvider.java:201)           在android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)           在android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)           在com.miracas.groupgiri.ui.facebook.FacebookActivity.onCreate(FacebookActivity.java:115)           在android.app.Activity.performCreate(Activity.java:7023)           在android.app.Activity.performCreate(Activity.java:7014)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2870)           在android.app.ActivityThread.-wrap11(未知来源:0)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1601)           在android.os.Handler.dispatchMessage(Handler.java:106)           在android.os.Looper.loop(Looper.java:172)           在android.app.ActivityThread.main(ActivityThread.java:6590)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)        造成原因:java.lang.NoSuchMethodException:[class android.app.Application]           在java.lang.Class.getConstructor0(Class.java:2320)           在java.lang.Class.getConstructor(Class.java:1725)

0 个答案:

没有答案