Question

I have script if toggle dialog onchecked will show custom dialog. If buttonUpdate remove di customdialog show but if i used buttonUpdate it will force close. please help

ToggleButton toogleStatus = (ToggleButton) findViewById(R.id.toggleStatus);
            // toogleStatus.setChecked(true);
            toogleStatus.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    // TODO Auto-generated method stub
                    Dialog dialog = new Dialog(DashboardActivity.this);
                    dialog.setContentView(R.layout.dialog_layout);
                    dialog.setTitle("Buat Status");
                    dialog.setCancelable(true);
                    //there are a lot of settings, for dialog, check them all out!

                    buttonUpdate = (Button)findViewById(R.id.buttonUpdate);
                    buttonUpdate.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                            // TODO Auto-generated method stub

                        }
                    });
                    //now that the dialog is set up, it's time to show it    
                    dialog.show();

                }
            });

Error message

06-17 19:35:15.059: E/AndroidRuntime(3790): FATAL EXCEPTION: main
06-17 19:35:15.059: E/AndroidRuntime(3790): java.lang.NullPointerException
06-17 19:35:15.059: E/AndroidRuntime(3790):     at net.drieanto.lagidimana.DashboardActivity$2.onCheckedChanged(DashboardActivity.java:129)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.widget.CompoundButton.setChecked(CompoundButton.java:125)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.widget.ToggleButton.setChecked(ToggleButton.java:72)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.widget.CompoundButton.toggle(CompoundButton.java:87)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.widget.CompoundButton.performClick(CompoundButton.java:99)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.view.View$PerformClick.run(View.java:14105)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.os.Handler.handleCallback(Handler.java:605)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.os.Looper.loop(Looper.java:137)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at java.lang.reflect.Method.invokeNative(Native Method)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at java.lang.reflect.Method.invoke(Method.java:511)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-17 19:35:15.059: E/AndroidRuntime(3790):     at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

I believe this will solve your problem

buttonUpdate  = (Button) dialog.findViewById(R.id.buttonUpdate);

Assumption dialog_layout contains Button buttonUpdate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top