I am using Butterknife to inject view for the toolbar. But the method getSupportActionBar(toolbar)
throws null pointer exception and the app unfortunately stopped. What can be done to solve this issue? I am using Android 4.2. So, is there any problem of 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'