CJR
CJR

Reputation: 3572

DAGGER: Error cannot resolve "this" when trying to inject into Fragment?

I get a "cannot resolve method" error on this line:

AndroidInjection.inject(this);

I am trying to inject into a fragment. Here is the whole class:

public class ShowWalletFragment extends BaseFragment {

    @Inject
    ShowWalletViewModelFactory showWalletViewModelFactory;
    ShowWalletViewModel showWalletViewModel;
    private Wallet wallet;
    private static final String TITLE_BALANCE = "Balance";

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
        //butterknife bind
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        showWalletViewModel = ViewModelProviders.of(this, showWalletViewModelFactory).
                get(ShowWalletViewModel.class);
    }

    @Override
    public void onAttach(Context context) {
        AndroidInjection.inject(this);
        super.onAttach(context);
    }

}

Why can't it resolve "this" ? Any suggestions? If you need more code from my app please let me know.

EDIT1:

implementation 'com.google.dagger:dagger:2.19'
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
implementation 'com.google.dagger:dagger-android:2.19'
implementation 'com.google.dagger:dagger-android-support:2.19'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.19'

Upvotes: 0

Views: 709

Answers (1)

Neha Chauhan
Neha Chauhan

Reputation: 647

Use this

import dagger.android.support.AndroidSupportInjection

AndroidSupportInjection.inject(this)

Upvotes: 8

Related Questions