Yes, sorry for not posting in before, line 163 is the one I marked : java.lang.NullPointerException at com.myapp.widget.CurrencyEditText$2.onClick(CurrencyEditText.java: 163) at com.android.internal.app.AlertController $ButtonHandler.handleMessage(AlertController.java:158) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:144) at android.app.ActivityThread.main(ActivityThread.java:4937) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method)
On Sep 15, 11:06 am, Mark Carter <mjc1...@googlemail.com> wrote: > Do you have access to the stacktrace? > > On Sep 15, 3:29 pm, Zsolt Vasvari <zvasv...@gmail.com> wrote: > > > > > Hello, I have a custom widget that can display a pop-up dialog. I > > have a single report of a NPE happening, and looking through my code, > > I don't know how that's possible unless there is a race condition > > involved somehow. Just wondering if anybody can point me to the > > problem. > > > Here's my code (irrelevant stuff omitted): > > > public class CurrencyEditText extends LinearLayout > > { > > Dialog mDialog; // If the dialog is NOT showing, this is NULL > > > protected void onDetachedFromWindow() > > { > > super.onDetachedFromWindow(); > > > // Dismiss, if showing > > if (mDialog != null) > > { > > mDialog.dismiss(); > > mDialog = null; > > } > > } > > > private void showDialog() > > { > > Builder builder = new Builder(context); > > > // Set dialog properties, omitted... > > > builder.setPositiveButton(R.string.set, new > > OnClickListener() > > { > > public void onClick(DialogInterface dialog, int > > buttonId) > > { > > // Dismiss > > CurrencyEditText.this.mDialog.dismiss(); > > CurrencyEditText.this.mDialog = null; > > > // Send message here, omitted... > > } > > }); > > > builder.setNegativeButton(android.R.string.cancel, new > > OnClickListener() > > { > > public void onClick(DialogInterface dialog, int > > buttonId) > > { > > // Dismiss -- NPE happens on next line as mDialog > > is NULL, which it shouldn't be > > CurrencyEditText.this.mDialog.dismiss(); > > CurrencyEditText.this.mDialog = null; > > > // Send message here, omitted... > > } > > }); > > > mDialog = builder.show(); > > } > > > } > > > That's it -- mDialog is not touched anywhere else. So either the > > click listener is called after onDetachedFromWindow() or before > > builder.show() can set mDialog. > > > Obviously, I could address the symptom by butting a NULL check around > > the crashing line, but I would like to understand what's going on here > > as I use the same pattern all over my app. > > > Thanks.- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en