마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

ButterKnife 사용하는데 오류가 뜹니다..ㅠㅠ 어떻게 하죠?

0 추천

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.butterknife/com.butterknife.MainActivity}: java.lang.IllegalStateException: Required view 'button' with ID 2131427415 for field 'button' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.

Caused by: java.lang.IllegalStateException: Required view 'button' with ID 2131427415 for field 'button' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.

 

위 같이 오류가 뜹니다 

자바 파일은 

public class MainActivity extends AppCompatActivity {
   @BindView(R.id.button)
    Button button;

    @BindView(R.id.title)
    TextView title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        title.setText("tete");
    }
}

요렇게 되어있고요 

ButterKnife 사이트에서 

dependencies {
  compile 'com.jakewharton:butterknife:8.5.1'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}

요거 추가하고 

buildscript {
  repositories {
    mavenCentral()
   }
  dependencies {
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
  }
}

요것도 추가 

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

이 plugin 첫번째 꺼는 추가가 안되고 2번째 꺼는 추가가 되더라고요 일단 2번째꺼만 추가를 하고 

싱크하고 실해했더니 저런 오류가 뜹니다 도대체 왜그럴까요?????

기객 (3,600 포인트) 님이 2017년 3월 9일 질문
@BindView 위에다가 @Nullable 추가를 하면 on a null object reference 라고 뜨네요.
음......

2개의 답변

0 추천
 
채택된 답변
또 자답 아 plugin 으로 alt+insert 해서 자동으로 분석해서 추가하면 되네요 으이아아아아아아ㅏ앙
기객 (3,600 포인트) 님이 2017년 3월 9일 답변
0 추천
setContentView 다음에 ButterKnife.bind(this); 가 빠진 거 아닌가요?
쎄미 (162,410 포인트) 님이 2017년 3월 9일 답변
음...그것도 나 넣었었고 전부 타이핑으로 넣었는데 널값으로 뜨더라고요. 그래서  youtube 사용법 보니 pugin깔고 alt insert 키 눌러서 분석후 추가하니깐 되더군요!
...