错误:找不到符号类DaggerBBCSportFragmentComponent

时间:2019-05-16 07:56:40

标签: java android dagger-2

我正在使用dagger2开发新闻应用程序,并且在logcat中遇到以下错误:

Dim dictionary As New Dictionary(Of String, String)
dictionary.Add("Black", "بلیک")
dictionary.Add("Blue", "بلیو")

以下是我收到错误的BBCSportFragment:

cannot find symbol class DaggerBBCSportFragmentComponent

下面是app.gradle文件:

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;
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 = (BBCSportFragmentComponent) DaggerApplicationComponent.builder().contextModule(new ContextModule(getContext())).build();
            bbcSportFragmentComponent = (BBCSportFragmentComponent) DaggerBBCSportFragmentComponent.builder().applicationComponent(applicationComponent).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;
}
}

我的代码可能是什么问题?

为什么BBCSportFragmentComponent导致错误?

如果您想让我发布更多代码,请告诉我。

0 个答案:

没有答案