If I were you, I would do a sanity check before that line and use analytics to report some environment stats (like model name, sdk version etc). Then you will maybe see that the problem is limited to certain devices (or maybe not). Still, it will be interesting to know.
I've had some really weird one-time errors reported (that really don't seem possible). The best you can do is program defensively around these problems as they come up. If they really are so rare (and device-specific), its probably not worth the effort to figure out exactly *why* its happened. On 15 September 2010 17:25, Zsolt Vasvari <[email protected]> wrote: > 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 <[email protected]> wrote: > > Do you have access to the stacktrace? > > > > On Sep 15, 3:29 pm, Zsolt Vasvari <[email protected]> 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 [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

