Я разрабатываю новостное приложение с использованием dagger2 и получаю следующую ошибку в logcat:
cannot find symbol class DaggerBBCSportFragmentComponent
Ниже приведен мой BBCSportFragment, где я получаю сообщение об ошибке:
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;
}
}
Ниже приведен файл app.gradle:
apply plugin: 'com.android.application'
android {
compileOptions.incremental = false
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 28
defaultConfig {
applicationId "edgar.yodgorbek.sportnews"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.jakewharton:butterknife:8.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
implementation 'com.google.dagger:dagger:2.15'
annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.10.0'
implementation group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.9.0'
}
В чем может быть проблема в моем коде?
Почему BBCSportFragmentComponent вызывает ошибку?
Если вы хотите, чтобы я опубликовал больше кода, сообщите мне, пожалуйста.