Я узнаю, как использовать dagger2 и Butterknife в моем проекте Android, все работает нормально, пока я не введу представление с аннотацией Butterknife BindView, он отображает ошибку, подобную этой;
Ошибка: (5, 57) ошибка: не удается найти класс символов DaggerNetComponent
это мой код DaggerNetComponent:
public class App extends Application {
private NetComponent mNetComponent;
@Override
public void onCreate() {
super.onCreate();
mNetComponent = DaggerNetComponent.builder().appModule(new AppModule(this)).netModule(new NetModule("http://example.com/"))
.build();
}
public NetComponent getNetComponent()
{
return mNetComponent;
}
}
и вот как я внедряю свой взгляд с помощью Butterknife:
public class MainActivity extends AppCompatActivity implements MainScreenContact.View {
@BindView(R.id.listContact)
ListView listView;
ArrayList<CharSequence> list;
ArrayAdapter<CharSequence> adapter;
@Inject
MainScreenPresenter mainPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
если я удалю аннотацию BindView и привязку ButterKnife к этому классу, то он работает нормально, но если я его использую, появится ошибка.
это мой Gradle.app
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'android-apt'
android {
compileSdkVersion 25
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.project.echo.contactmanagement"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.0.2'
//OkHttp
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okio:okio:1.7.0'
//Gson
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
//RxJava
compile 'io.reactivex:rxjava:1.1.2'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
testCompile 'junit:junit:4.12'
//Dagger
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
//butterknife
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'
}
Пожалуйста, помогите мне, любой ответ будет оценен...
Спасибо..
R.id.listContact
указывает на экземпляр ListView, и попробуйте очистить и перестроить. Кроме того, проверьте наличие других ошибок времени компиляции. - person David Rawson   schedule 06.12.2016build.gradle
. Еще лучше, создайте минимальный проект, который воспроизводит проблему — мы уже некоторое время используем эти две библиотеки вместе в одном проекте, и таких проблем не возникало. - person David Rawson   schedule 06.12.2016