bhaskarc
bhaskarc

Reputation: 9521

Illegal State Exception: Custom Dialog

I have created a custom dialog layout. When invoked, the dialog pops up fine. But when I try to set the content inside the dialog using the two lines commented below, it throws an illegal state exception.

 private void showCustomDialog(String content){
     final Dialog d = new Dialog(this);
     d.setContentView(R.layout.spread_info_popup);
     d.show();

     // TextView contentTv = (TextView) findViewById(R.id.my_dialog_content);
     // contentTv.setText(content);

     }

What is wrong here ?

Do i need to inflate the layout spread_info_popup before referring to TextView within it with an id of my_dialog_content ?

the Stacktrace:

03-04 15:03:54.690: E/AndroidRuntime(4194): FATAL EXCEPTION: main
03-04 15:03:54.690: E/AndroidRuntime(4194): java.lang.IllegalStateException: Could not execute method of the activity
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.view.View$1.onClick(View.java:3591)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.view.View.performClick(View.java:4084)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.view.View$PerformClick.run(View.java:16966)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.os.Handler.handleCallback(Handler.java:615)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.os.Looper.loop(Looper.java:137)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.app.ActivityThread.main(ActivityThread.java:4745)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at java.lang.reflect.Method.invokeNative(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at java.lang.reflect.Method.invoke(Method.java:511)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at dalvik.system.NativeStart.main(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194): Caused by: java.lang.reflect.InvocationTargetException
03-04 15:03:54.690: E/AndroidRuntime(4194):     at java.lang.reflect.Method.invokeNative(Native Method)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at java.lang.reflect.Method.invoke(Method.java:511)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at android.view.View$1.onClick(View.java:3586)
03-04 15:03:54.690: E/AndroidRuntime(4194):     ... 11 more
03-04 15:03:54.690: E/AndroidRuntime(4194): Caused by: java.lang.NullPointerException
03-04 15:03:54.690: E/AndroidRuntime(4194):     at com.me.reader.ui.activity.CompleteList.showSpreadInfoPopup(CompleteList.java:122)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at com.me.reader.ui.activity.CompleteList.setSpreadDescriptionfromXML(CompleteList.java:104)
03-04 15:03:54.690: E/AndroidRuntime(4194):     at com.me.reader.ui.activity.CompleteList.onAboutIconClicked(CompleteList.java:81)
03-04 15:03:54.690: E/AndroidRuntime(4194):     ... 14 more

Upvotes: 0

Views: 141

Answers (1)

Blackbelt
Blackbelt

Reputation: 157467

you should look for the view inside the Dialog:

   TextView contentTv = (TextView) dialog.findViewById(R.id.my_dialog_content);
   contentTv.setText(content);

here the documentation.

Upvotes: 2

Related Questions