1. Check out our companion app, Forums for Android! Download from Google Play

Help learning how custom Alert Boxes work

Discussion in 'Application Development' started by Arehexes, Dec 22, 2012.

  1. Arehexes

    Arehexes Well-Known Member
    Thread Starter
    36

    Jul 24, 2010
    110
    2
    36
    So I'm trying to figure out how to make a custom dialog pop up on a function call, yet my app crashes when I try to pop it up on the app.

    [HIGH] public void eventpopUpDialog(BluetoothAdapter bluetooth){
    //Sets up the layout for the popup box
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.bluetooth_popup_status);

    //Make the variables for each UI element on the pop up box
    TextView output = (TextView) findViewById(R.id.popupDialogTV);
    final Button close = (Button) findViewById(R.id.closePopUp);

    //testing to see what is crashing
    output.setText("test");

    //The Event to close the dialog
    close.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    dialog.dismiss();
    }
    });

    dialog.show();
    }
    [/HIGH]

    This is the code in question, I'm at a lost for why it's not working >_>.
     

    Advertisement

  2. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    Can you please post a copy of the logcat output?
     
  3. Arehexes

    Arehexes Well-Known Member
    Thread Starter
    36

    Jul 24, 2010
    110
    2
    36
    Wow I'm sorry for this late response I was busy the last two weeks, here is the logcat file from debugging the app.

    PHP:
    1. 01-07 17:22:38.343: E/AndroidRuntime(14383): FATAL EXCEPTION: main
    2. 01-07 17:22:38.343: E/AndroidRuntime(14383): java.lang.NullPointerException
    3. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at com.example.bluetooth.practice.MainActivity.eventpopUpDialog(MainActivity.java:122)
    4. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at com.example.bluetooth.practice.MainActivity$3.onClick(MainActivity.java:50)
    5. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.view.View.performClick(View.java:4084)
    6. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.view.View$PerformClick.run(View.java:16966)
    7. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.os.Handler.handleCallback(Handler.java:615)
    8. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.os.Handler.dispatchMessage(Handler.java:92)
    9. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.os.Looper.loop(Looper.java:137)
    10. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at android.app.ActivityThread.main(ActivityThread.java:4745)
    11. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at java.lang.reflect.Method.invokeNative(Native Method)
    12. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at java.lang.reflect.Method.invoke(Method.java:511)
    13. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    14. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    15. 01-07 17:22:38.343: E/AndroidRuntime(14383):    at dalvik.system.NativeStart.main(Native Method)
    16.  
     
  4. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    Whats on line 122 of MainActivity.java?
     
  5. Arehexes

    Arehexes Well-Known Member
    Thread Starter
    36

    Jul 24, 2010
    110
    2
    36
    Again I'm super sorry for the late response last time.

    This is what was in line 122

    PHP:
    1. output.setText("test");
    I'm guessing it's not working cause it's trying to talk to a object that is null. But I'm setting the object on line 118

    PHP:
    1. TextView output = (TextView) findViewById(R.id.popupDialogTV);
     
  6. myrecek

    myrecek Active Member
    16

    May 10, 2012
    29
    2
    16
    I am not sure if it helps but you could try dialog.findViewById

    [HIGH]TextView output = (TextView) dialog.findViewById(R.id.popupDialogTV); [/HIGH]
     
    Arehexes likes this.
  7. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    This is what I was going to say. This should fix your problem.
     
  8. Arehexes

    Arehexes Well-Known Member
    Thread Starter
    36

    Jul 24, 2010
    110
    2
    36
    Thanks this worked, wonder why it was so hard to find the answer too >_>.
     

Share This Page

Loading...