Android ButterKnife @OnClick()不能完全正常运行

时间:2019-09-19 15:16:57

标签: android butterknife

 @BindView(R.id.text_view)
TextView text_view;

@BindView(R.id.app_bar)
Toolbar toolbar;

 private FirebaseUser firebaseUser;

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

    ButterKnife.bind(this);
    setSupportActionBar(toolbar);



}

@OnClick(R.id.test_btn)
void btnTest(){
    Toast.makeText(this, "all ok", Toast.LENGTH_SHORT).show();
}
  

E / Android运行时:致命异常:主要       流程:com.example.calories,PID:10164       java.lang.BootstrapMethodError:呼叫站点#1引导程序方法异常           在butterknife.internal.DebouncingOnClickListener。(DebouncingOnClickListener.java:12)           在com.example.calories.MainActivity_ViewBinding。(MainActivity_ViewBinding.java:34)           在java.lang.reflect.Constructor.newInstance0(本地方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:343)           在butterknife.ButterKnife.bind(ButterKnife.java:170)           在butterknife.ButterKnife.bind(ButterKnife.java:99)           在com.example.calories.MainActivity.onCreate(MainActivity.java:35)           在android.app.Activity.performCreate(Activity.java:7136)           在android.app.Activity.performCreate(Activity.java:7127)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)           在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)           在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)           在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1808)           在android.os.Handler.dispatchMessage(Handler.java:106)           在android.os.Looper.loop(Looper.java:193)           在android.app.ActivityThread.main(ActivityThread.java:6669)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493)

1 个答案:

答案 0 :(得分:0)

黄油刀要求您在版本9.0.0及更高版本中启用Java 8。您可以在https://developer.android.com/studio/write/java8-support上了解有关如何启用此功能的更多信息。

您需要添加类似内容

  android { 
compileOptions {
 targetCompatibility = "8" sourceCompatibility = "8"
 } 
}

到您的应用程序build.gradle。