error: cannot find symbol method contextModule(ContextModule)

徘徊边缘 提交于 2019-12-13 20:30:18

问题


I am developing news app but I am getting the following error from Logcat

error: cannot find symbol method contextModule(ContextModule)

below screenshot of error screenshot of error

below BBCFragment.java class

public class BBCSportFragment extends Fragment implements ArticleAdapter.ClickListener {

public List<Article> articleList = new ArrayList<>();
@ActivityContext
public Context activityContext;
@ApplicationContext
public Context mContext;

@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@Inject
BBCSportFragmentComponent bbcSportFragmentComponent;
BBCFragmentContextModule bbcFragmentContextModule;
private SportNews sportNews;
private ArticleAdapter articleAdapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_bbcsport, container, false);
    Activity activity = getActivity();
    ButterKnife.bind(this, view);
    SportInterface sportInterface = SportClient.getApiService();
    Call<SportNews> call = sportInterface.getArticles();
    call.enqueue(new Callback<SportNews>() {
        @Override
        public void onResponse(Call<SportNews> call, Response<SportNews> response) {
            sportNews = response.body();
            if (sportNews != null && sportNews.getArticles() != null) {
                articleList.addAll(sportNews.getArticles());
            }
            articleAdapter = new ArticleAdapter(articleList, sportNews);
            ApplicationComponent applicationComponent = MyApplication.get(Objects.requireNonNull(activity)).getApplicationComponent();
            bbcSportFragmentComponent =
                    DaggerBBCSportFragmentComponent.builder()
                            .applicationComponent(applicationComponent)
                            .contextModule(new ContextModule(getContext()))
                            .build();
            bbcSportFragmentComponent.injectBBCSportFragment(BBCSportFragment.this);
            RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(articleAdapter);
        }

        @Override
        public void onFailure(Call<SportNews> call, Throwable t) {
            Log.e("Error", "error");
        }
    });


    return view;


}

}

below ApplicationComponent.java class

@ApplicationScope
@Component(modules = {ContextModule.class, SportClient.class})
public interface ApplicationComponent {


    public SportInterface sportInterface();

    @ApplicationContext
    public Context getContext();

    public void injectApplication(MyApplication myApplication);


}

below MyApplication.java class


public class MyApplication extends Application {

    ApplicationComponent applicationComponent;

    public static MyApplication get(Activity activity) {
        return (MyApplication) activity.getApplication();
    }

    @Override
    public void onCreate() {
        super.onCreate();

        applicationComponent = DaggerApplicationComponent.builder().contextModule(new ContextModule(this)).build();
        applicationComponent.injectApplication(this);

    }

    public ApplicationComponent getApplicationComponent() {
        return applicationComponent;
    }
}

来源:https://stackoverflow.com/questions/55843080/error-cannot-find-symbol-method-contextmodulecontextmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!