2016-10-08 1 views
0

Butterknife私は@bindViewを使用してボタンに注釈を付けます。 しかし、それはエラーが起こった。 Required view 'hello' with ID 2131427413 for field 'hello' was not found.butterknifeフィールド 'hello'のID '2131427413'が必要なビュー 'hello'が見つかりませんでした

@BindView(R.id.hello) 
Button hello; 
@Inject 
GitHubApiService gitHubApiService; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    ButterKnife.bind(this); 
    hello.setText("hello"); 
} 

butterknifeの依存関係

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt'//这个是自定义注解用的编译插件 

buildscript { 

    repositories { 

     jcenter() 

    } 

    dependencies { 

     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
     classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0' 

    } 

} 
+1

あなたは '活動のsetContentView' –

+0

あなたはプロジェクトをきれいにしようとすることができませんでした –

答えて

1

あなたは以下のようなButterKnife.bind(this)を呼び出す前に、コンテンツビューを設定する必要があります。

setContentView(R.layout.your_view); 
ButterKnife.bind(this); 
0

ありがとう、私はその理由を自分自身を発見!。

前にbuild.gradle of app moduleに以下を追加してください。 しかし、あなたは右のレイアウトを渡しているsetContentView(R.layout.your_view);でいることを確認してください。またbuild.gradle of project

>classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
    >classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0' 

    buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.0' 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
     classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 
0

に追加する必要があり、次の

関連する問題