android - Butter Knife不支持sdk25.0.0吗
PHPz
PHPz 2017-04-17 17:49:23
0
1
641

我新建了一个hellowworld不支持啊

package com.xiaogu.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.Button;

import com.xiaogu.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends Activity {
    @BindView(R.id.btn)
    Button btn;

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

        ButterKnife.bind(this);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(findViewById(R.id.btn), "SnackbarClicked", Snackbar.LENGTH_SHORT).show();
            }
        });
    }
   } 
10-21 14:58:30.440 18007-18007/com.xiaogu E/AndroidRuntime: FATAL EXCEPTION: main
                                                            Process: com.xiaogu, PID: 18007
                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xiaogu/com.xiaogu.ui.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                at android.os.Looper.loop(Looper.java:148)
                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                             Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                at com.xiaogu.ui.MainActivity.onCreate(MainActivity.java:25)
                                                                at android.app.Activity.performCreate(Activity.java:6251)
                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
PHPz
PHPz

学习是最好的投资!

全員に返信(1)
巴扎黑

サポートは問題ありません

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート