• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

AlertDialog.Builder builder causes my app to crash o my mobile phone

This chunk of code that puts up an alert dialog box is causing my app to crash on my mobile phone when I try to run it.
Why?
Is the issue because I am trying to put up the alert dialog box on onCreate()?

Code:
public void onCreate()
{
    super.onCreate();
    //for (int nI = 0; nI < m_nMaxStations; nI++)
    //    m_arrayStations[nI] = new CStation(nI + 1);

    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
    }
    else
    {
        builder = new AlertDialog.Builder(this);
    }
    builder.setTitle("Delete entry");
    builder.setMessage("Are you sure you want to delete this entry?");
    builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
    {
        public void onClick(DialogInterface dialog, int which)
        {
            // continue with delete
        }
    });
    builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener()
    {
        public void onClick(DialogInterface dialog, int which)
        {
            // do nothing
        }
    });
    builder.setIcon(android.R.drawable.ic_dialog_alert);
    builder.show();

    //GetSettings();
    //Dump();
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones