1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by Gregary Boyles, Oct 2, 2017.

  1. Gregary Boyles

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    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 (Text):
    1.  
    2. public void onCreate()
    3. {
    4.     super.onCreate();
    5.     //for (int nI = 0; nI < m_nMaxStations; nI++)
    6.     //    m_arrayStations[nI] = new CStation(nI + 1);
    7.  
    8.     AlertDialog.Builder builder;
    9.     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    10.     {
    11.         builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
    12.     }
    13.     else
    14.     {
    15.         builder = new AlertDialog.Builder(this);
    16.     }
    17.     builder.setTitle("Delete entry");
    18.     builder.setMessage("Are you sure you want to delete this entry?");
    19.     builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
    20.     {
    21.         public void onClick(DialogInterface dialog, int which)
    22.         {
    23.             // continue with delete
    24.         }
    25.     });
    26.     builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener()
    27.     {
    28.         public void onClick(DialogInterface dialog, int which)
    29.         {
    30.             // do nothing
    31.         }
    32.     });
    33.     builder.setIcon(android.R.drawable.ic_dialog_alert);
    34.     builder.show();
    35.  
    36.     //GetSettings();
    37.     //Dump();
    38. }
    39.  
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,853
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,853
    11,457
    1,988
    Male
    Software developer
    South West of England
    Please show the stack trace from the Logcat output.
     

Share This Page

Loading...