Android 对话框界面上的复选框错误

Android 对话框界面上的复选框错误,android,checkbox,sharedpreferences,android-alertdialog,oncheckedchanged,Android,Checkbox,Sharedpreferences,Android Alertdialog,Oncheckedchanged,我在一个我找不到的小问题中挣扎!在我的主要活动中,我想显示一个AlertDialog,如果用户不想再次显示该对话框,则选中该复选框 我可以使对话框与复选框一起出现,等等。。但由于某些原因,当我尝试将oncheckedchangelister添加到复选框时,我的应用程序在启动前关闭:( 以下是我的代码的相关部分: 正在初始化SharedReference的变量: public final static String WEL_PREF = "Welcome Dialog Preference"; p

我在一个我找不到的小问题中挣扎!在我的主要活动中,我想显示一个AlertDialog,如果用户不想再次显示该对话框,则选中该复选框

我可以使对话框与复选框一起出现,等等。。但由于某些原因,当我尝试将oncheckedchangelister添加到复选框时,我的应用程序在启动前关闭:(

以下是我的代码的相关部分:

正在初始化SharedReference的变量:

public final static String WEL_PREF = "Welcome Dialog Preference";
public static int welcomeChecked = 0;
内部OnCreate:

SharedPreferences welcomePref = getSharedPreferences(WEL_PREF, MODE_PRIVATE);
welcomeChecked = welcomePref.getInt("tut", 0);

... 


    if(welcomeChecked == 1) {  

    showAlertDialog(); 

    }
showAlertDialog()函数:

  private void showAlertDialog() {

    final Intent tutorial = new Intent(MainActivity.this, TutorialActivity.class);  
    View checkBoxView = View.inflate(this, R.layout.welcome_checkbox, null);    
    CheckBox welcomeCheck = (CheckBox) findViewById(R.id.tutCheck);         
    welcomeCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            SharedPreferences welcomePref = getSharedPreferences(WEL_PREF, MODE_PRIVATE);
            SharedPreferences.Editor editor = welcomePref.edit();

            if(isChecked) {
            editor.putInt("tut", 1);
            editor.commit();
            } else { 
                 editor.putInt("tut", 0);
                 editor.commit();
            }

        }
    });

    AlertDialog.Builder welcomeDialog = new AlertDialog.Builder(this);
    welcomeDialog.setTitle("Welcome");      
    welcomeDialog.setMessage("Welcome to Formula Calculator, if you want to know how to use my features " +
            "click in the Tutorial button.");
    welcomeDialog.setView(checkBoxView);
    welcomeDialog.setCancelable(false);
    welcomeDialog.setPositiveButton("Tutorial", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            startActivity(tutorial);
        }
    });

    welcomeDialog.setNegativeButton("Close", new DialogInterface.OnClickListener() {            
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();                
        }
    });              
    AlertDialog welDialog = welcomeDialog.create();                 
    welDialog.show();
}
非常感谢您的帮助!我无法找到应用程序关闭的解决方案

以下是logcat,如果有帮助:

05-19 15:37:55.807: W/ActivityThread(8009): Application com.gabilheri.marcuscalculatorv2 can be 

debugged on port 8100...
05-19 15:37:56.127: D/AndroidRuntime(8009): Shutting down VM
05-19 15:37:56.127: W/dalvikvm(8009): threadid=1: thread exiting with uncaught exception (group=0x40c32930)
05-19 15:37:56.137: E/AndroidRuntime(8009): FATAL EXCEPTION: main
05-19 15:37:56.137: E/AndroidRuntime(8009): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gabilheri.marcuscalculatorv2/com.gabilheri.marcuscalculatorv2.MainActivity}: java.lang.NullPointerException
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.os.Looper.loop(Looper.java:137)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread.main(ActivityThread.java:5041)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at java.lang.reflect.Method.invoke(Method.java:511)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at dalvik.system.NativeStart.main(Native Method)
05-19 15:37:56.137: E/AndroidRuntime(8009): Caused by: java.lang.NullPointerException
05-19 15:37:56.137: E/AndroidRuntime(8009):     at com.gabilheri.marcuscalculatorv2.MainActivity.showAlertDialog(MainActivity.java:744)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at com.gabilheri.marcuscalculatorv2.MainActivity.onCreate(MainActivity.java:171)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.Activity.performCreate(Activity.java:5104)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-19 15:37:56.137: E/AndroidRuntime(8009):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-19 15:37:56.137: E/AndroidRuntime(8009):     ... 11 more
05-19 15:37:56.187: D/dalvikvm(8009): GC_CONCURRENT freed 219K, 5% free 7518K/7864K, paused 14ms+2ms, total 80ms

如果对话框布局中有
tutCheck
复选框,则将其初始化为:

View checkBoxView = View.inflate(this, R.layout.welcome_checkbox, null); 
CheckBox welcomeCheck = (CheckBox)checkBoxView.findViewById(R.id.tutCheck); 

谢谢!!它解决了我的问题!!:)我知道这是一个愚蠢的错误,但我看了所有的东西,却找不到它!