I use Butterknife to enter a view for a toolbar. But the getSupportActionBar(toolbar) method throws an exception from the null pointer, and the application, unfortunately, is stopped. What can be done to solve this problem? I am using Android 4.2. So, is there a problem using Butterknife with Jellybean?
Mainactivity
public class MainActivity extends AppCompatActivity { @BindView(R.id.tool_bar_demo) Toolbar toolbar; @BindDrawable(R.drawable.backspace) Drawable backspace_btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); setSupportActionBar(toolbar); toolbar.setTitle("ABC"); } }
activity_main
<android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="58dp" android:id="@+id/tool_bar_demo" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:titleTextColor="@color/colorAccent" /> </RelativeLayout>
gradle
minSdkVersion 15 targetSdkVersion 23 apply plugin: 'com.neenbedankt.android-apt' compile 'com.android.support:design:23.4.0' compile 'com.jakewharton:butterknife:8.0.1' apt 'com.jakewharton:butterknife-compiler:8.0.1' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
source share