I downloaded the ButterKnife library, installed the plugin, like on the plugin's website. As a result, I get NullPointerExeption.

Is there any plugin on the Internet that, according to R.layout.main will create in the Java class all the id elements?

Button , ListView , etc. like the ButterKnife plugin, only it doesn't work for some reason.

It gives an error

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com../com...Activites.News1}: java.lang.NullPointerException Caused by: java.lang.NullPointerException at com...Activites.News1$override.onCreate(News1.java:36) at com...Activites.News1$override.access$dispatch(News1.java) at com...Activites.News1.onCreate(News1.java:0) 

Here is the code of the programm itself.

  public class News1 extends AppCompatActivity{ String textShare = ""; boolean tabLikeBool = false; @BindView(R.id.tab_like) TextView tabLike; @BindView(R.id.tab_msg) TextView tabMsg; @BindView(R.id.tab_share) TextView tabShare; // TextView tabLike,tabMsg,tabShare; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news1); ButterKnife.bind(this); // tabLike= (TextView) findViewById(R.id.tab_like); tabLike.setOnClickListener(this); // tabMsg= (TextView) findViewById(R.id.tab_msg); tabMsg.setOnClickListener(this); // tabShare= (TextView) findViewById(R.id.tab_share); tabShare.setOnClickListener(this); tabLike.setText("4"); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } 

Here's the compile 'com.jakewharton:butterknife:8.1.0'

Why does everyone work? I don't have

  • four
    Describe your problem in more detail, it is desirable to attach error logs. PS Butterknife one of the best libraries - Alexey Shtanko
  • @AdamLuisSean, Well, the NullPointer error. gives out - Vasya
  • four
    Everything works for everyone, and you are so special that something does not work for you. Maybe you are doing something wrong? Show your code. - temq
  • @temq. I'm that from the moon chtoli? How can you work? Schyas throw off. Normal nullPointer which cannot find View in Layout. Although he is there - Vasya
  • @pavlofff, Well, you yourself said that the question is not clear. I redid it. And what's wrong? - Vasya

1 answer 1

The problem is that you do not have a fully connected library, since for some time it’s not enough to simply write the dependences to the project module’s build.gradle.
To connect the ButterKnife library, you need to do several actions, according to the instructions.

Add classpatch to the build.gradle of the entire project (file in the project root folder):

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } 

}

Connect the plugin and add the following dependencies to the module's build.gradle (file in the application source folder):

 apply plugin: 'android-apt' android { ... } dependencies { compile 'com.jakewharton:butterknife:8.1.0' apt 'com.jakewharton:butterknife-compiler:8.1.0' } 

In connection with these manipulations, the library is connected incorrectly through the GUI interface for adding dependencies in the Project Structure window; you can correctly connect it only by writing the necessary lines directly in the project files.