ButterKnife 8.0.1이 작동하지 않음
를 사용 butterknife 8.0.1
하고 있지만 nullpointerexception
이 나타납니다.
이 줄은 내 build.grade 파일에 있습니다. compile 'com.jakewharton:butterknife:8.0.1'
이것은 내 Main Class:
(내가 포함을 제대로 썼다)
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends BaseActivity {
@BindView(R.id.MainScreenTextView) TextView mainText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
**mainText.setText("Butter knife is working fine");**
}
그리고 이것은 MainActivity.xml
:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/MainScreenTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is the Main Screen"
android:textColor="#000000"
android:background="#666666"
android:padding="5dp"
android:textSize="20dp"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
당 추가 정보 , 당신은을 포함 할 필요가 butterknife-compiler
생성 된 코드가 자동으로 생성 될 위해서는 :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
이것이 없으면로드 할 생성 된 코드가 없으므로 필드가 설정되지 않습니다.
Logcat을 호출 ButterKnife.setDebug(true)
하고 검색 하여 ButterKnife가 작동하는지 확인할 수 있습니다 .
이 라이브러리를 Fragment에서 사용했으며 NPE가 있습니다. 내 코드는 다음과 같습니다.
ButterKnife.bind(view);
그러나 그것은 잘못되었습니다. 라이브러리는 2 개의 객체를 알아야합니다.
1) 대상-@BindView 주석 포함
2) 소스-보기 포함
다음과 같이 작성하는 것이 옳습니다.
ButterKnife.bind(this, view);
이-당신의 조각,보기-이 조각의보기.
App Level(build.gradle)
apply plugin: 'android-apt'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
Project Level(build.gradle)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
for me the problem was that I was using
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
instead of
apt 'com.jakewharton:butterknife-compiler:8.7.0
Config Butterknife on build.gradle file like this,
compile("com.jakewharton:butterknife:8.5.1")
annotationProcessor "com.jakewharton:butterknife-compiler:8.5.1"
It works for me.
I had this issue too, just because I've added butterknife from Android Studio's Dependency management and not by copy-pasting gradle lines from Butterknife website. So I had to add compile 'com.jakewharton:butterknife:8.5.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
instead of just compile 'com.jakewharton:butterknife:8.5.1'
If you use kotlin:
make sure to use this dependency in module app:
dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
kapt 'com.jakewharton:butterknife-compiler:10.0.0'
}
From JakeWharton
Yes that plugin is no longer needed. You're already using annotationProcessor for the 'butterknife-compiler' artifact which is built-in to the Android Gradle plugin.
Then the solution is delete apt classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
I have just faced this problem, after updating my project to Gradle version 3.0.1
. I was able to fix it by just including in Gradle app
file the line:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
The final result was:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
...
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
I hope this helps somebody, although this question being old.
Add annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
In your gradle file it worked for me
참고URL : https://stackoverflow.com/questions/37013619/butterknife-8-0-1-not-working
'Program Tip' 카테고리의 다른 글
부모 외부로 이동하면 Android보기가 사라짐 (0) | 2020.12.06 |
---|---|
마지막 플렉스 항목을 컨테이너 끝에 배치 (0) | 2020.12.06 |
API 26 (Android) 용 Gradle 설정 (0) | 2020.12.06 |
Ubuntu / Debian에 Mono 3.x 설치 (0) | 2020.12.06 |
DataGrid WPF에서 선택한 행 항목 가져 오기 (0) | 2020.12.06 |