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

Apps Help learning how custom Alert Boxes work

Arehexes

Well-Known Member
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 >_>.
 
Can you please post a copy of the logcat output?

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:
01-07 17:22:38.343: E/AndroidRuntime(14383): FATAL EXCEPTION: main
01-07 17:22:38.343: E/AndroidRuntime(14383): java.lang.NullPointerException
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at com.example.bluetooth.practice.MainActivity.eventpopUpDialog(MainActivity.java:122)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at com.example.bluetooth.practice.MainActivity$3.onClick(MainActivity.java:50)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.view.View.performClick(View.java:4084)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.view.View$PerformClick.run(View.java:16966)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.os.Handler.handleCallback(Handler.java:615)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.os.Looper.loop(Looper.java:137)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at java.lang.reflect.Method.invoke(Method.java:511)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-07 17:22:38.343: E/AndroidRuntime(14383): 	at dalvik.system.NativeStart.main(Native Method)
 
Whats on line 122 of MainActivity.java?

Again I'm super sorry for the late response last time.

This is what was in line 122

PHP:
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:
TextView output = (TextView) findViewById(R.id.popupDialogTV);
 
I am not sure if it helps but you could try dialog.findViewById

[HIGH]TextView output = (TextView) dialog.findViewById(R.id.popupDialogTV); [/HIGH]
 
Back
Top Bottom