0

我正在尝试使 AlertDialog Positive & Negative Buttons 成为 ImageButtons 但是日志猫给了我一个 NullPointerException 指向该方法&这里是我的代码

AlertDialog.Builder builder = new AlertDialog.Builder(
                Main.this);
        AlertDialog d = builder.create();


        builder.setTitle("Notification");
        builder.setMessage("You have a running session NOW .. Check to Enter").setPositiveButton("YES",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                         .....
                    }
                }).setNegativeButton("NO", null);
        builder.create().show();

        Button yes = d.getButton(AlertDialog.BUTTON_POSITIVE);
        yes.setCompoundDrawablesWithIntrinsicBounds(R.drawable.navigationaccept, 0, 0, 0);



        Button no = d.getButton(AlertDialog.BUTTON_NEGATIVE);
        no.setCompoundDrawablesWithIntrinsicBounds(R.drawable.navigation_cancel, 0, 0, 0);
    }
});

这是我的原木猫

11-22 21:22:55.227: E/AndroidRuntime(1125): FATAL EXCEPTION: main
11-22 21:22:55.227: E/AndroidRuntime(1125): java.lang.NullPointerException
11-22 21:22:55.227: E/AndroidRuntime(1125):     at     guc.edu.iremote.Main$3.run(Main.java:294)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at     android.os.Handler.handleCallback(Handler.java:615)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at android.os.Looper.loop(Looper.java:137)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at     android.app.ActivityThread.main(ActivityThread.java:4745)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at     java.lang.reflect.Method.invokeNative(Native Method)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at java.lang.reflect.Method.invoke(Method.java:511)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-22 21:22:55.227: E/AndroidRuntime(1125):     at     dalvik.system.NativeStart.main(Native Method)
4

0 回答 0