Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:31:51+00:00 2026-06-07T02:31:51+00:00

I’m tried to display AlertDialog when an button in QuickAction is pressed.But my application

  • 0

I’m tried to display AlertDialog when an button in QuickAction is pressed.But my application crashes while trying to accomplish this task.I dont know what is causing the error.I also tried to use Thread.sleep to give time to QuickAction to dimiss properly and display AlertDialog but it didnt work.

I did research and found one question: Starting Dialog from QuickAction Button

This question is somewhat similar to mine but when i tried to replace getApplicationContext() with the MyClass.class i get an error saying that constructor AlertDialog.builder(Class) is undefined.

Following is the piece of code QuickAction and AlertDialog:

ActionItem editQItem = new ActionItem(ID_EDIT_Q, "Edit", getResources()
            .getDrawable(R.drawable.qa_edit));
    ActionItem deleteQItem = new ActionItem(ID_DELETE_Q, "Delete",
            getResources().getDrawable(R.drawable.qa_delete_answer));
    System.out.println("Blah 1");

    mQuickActionQ = new QuickAction(this);
    mQuickActionQ.addActionItem(editQItem);
    mQuickActionQ.addActionItem(deleteQItem);
    System.out.println("Blah 2");

    // setup the action item click listener
    mQuickActionQ
            .setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
                public void onItemClick(QuickAction quickAction, int pos,
                        int actionId) {
                    ActionItem actionItem = quickAction.getActionItem(pos);
                    System.out.println("Blah 3");
                    if (actionId == ID_EDIT_Q) {
//Here im getting error from here onwards when trying to display AlertDialog
                        et_question = new EditText(getApplicationContext());
                        et_tag1 = new EditText(getApplicationContext());
                        et_tag2 = new EditText(getApplicationContext());
                        et_tag3 = new EditText(getApplicationContext());
                        et_question.setText(question);
                        et_tag1.setText(q_tag1);
                        et_tag2.setText(q_tag2);
                        et_tag3.setText(q_tag3);
                        tv_question = new TextView(getApplicationContext());
                        tv_question.setText("Question:");
                        tv_question.setTextSize(15);
                        tv_tags = new TextView(getApplicationContext());
                        tv_tags.setText("Tags:");
                        tv_tags.setTextSize(15);
                        ll_edit = new LinearLayout(getApplicationContext());
                        ll_edit.setOrientation(1);
                        ll_edit.addView(tv_question);
                        ll_edit.addView(et_question);
                        ll_edit.addView(tv_tags);
                        ll_edit.addView(et_tag1);
                        ll_edit.addView(et_tag2);
                        ll_edit.addView(et_tag3);
                        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
                        builder.setMessage("Edit");
                        builder.setCancelable(true);
                        builder.setView(ll_edit);
                        builder.setPositiveButton("Save Changes",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        boolean Success = true;
                                        Editable ttv = et_question.getText();
                                        final String answer = new StringBuilder().append(
                                                ttv).toString();
                                        if (answer.equals("")) {
                                            Dialog mTag = new Dialog(
                                                    getApplicationContext());
                                            mTag.setTitle("One of the field is empty!");
                                            TextView tv2 = new TextView(
                                                    getApplicationContext());
                                            tv2.setText("Blank fields are not allowed.");
                                            mTag.setContentView(tv2);
                                            mTag.setCancelable(true);
                                            mTag.show();
                                        } else {
                                            String uname = qun.getText().toString();
                                            String question = qu.getText().toString();
                                            String question_time = qpo.getText().toString();
                                            String new_question = et_question.getText()
                                                    .toString();
                                            String new_tag1 = et_tag1.getText().toString();
                                            String new_tag2 = et_tag2.getText().toString();
                                            String new_tag3 = et_tag3.getText().toString();
                                            uf = new UserFunctions();
                                            HashMap<String, String> hm = new HashMap<String, String>();
                                            db = new DatabaseHandler(
                                                    getApplicationContext());
                                            db.getReadableDatabase();
                                            hm = db.getUserDetails();
                                            db.close();
                                            String username = hm.get("username");
                                            JSONObject json = uf.updateQuestion(username,
                                                    question, question_time, new_question,
                                                    new_tag1, new_tag2, new_tag3);
                                            dialog.dismiss();
                                            pd = ProgressDialog.show(ViewMyQuestion.this,
                                                    "Please wait...",
                                                    "Updating your question!", true, false);
                                            Thread thread = new Thread(ViewMyQuestion.this);
                                            thread.start();
                                            tagcombo = new_tag1 + "," + new_tag2 + ","
                                                    + new_tag3;
                                            qun.setText(username);
                                            qtag.setText(tagcombo);
                                            qu.setText(new_question);
                                        }// end of if else
                                    }
                                });

                        builder.setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        System.out.println("Blah 4");
                        Toast.makeText(getApplicationContext(),
                                actionItem.getTitle() + " selected",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

    mQuickActionQ.setOnDismissListener(new QuickAction.OnDismissListener() {
        public void onDismiss() {
            Toast.makeText(getApplicationContext(), "Ups..dismissed",
                    Toast.LENGTH_SHORT).show();
        }
    });

Following is the Logcat messages:

07-05 18:01:27.158: E/AndroidRuntime(389): FATAL EXCEPTION: main
07-05 18:01:27.158: E/AndroidRuntime(389): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.view.ViewRoot.setView(ViewRoot.java:509)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.app.Dialog.show(Dialog.java:241)
07-05 18:01:27.158: E/AndroidRuntime(389):  at com.vervecoders.cuqu.ViewMyQuestion$3.onItemClick(ViewMyQuestion.java:222)
07-05 18:01:27.158: E/AndroidRuntime(389):  at com.vervecoders.cuqu.QuickAction$2.onClick(QuickAction.java:162)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.view.View.performClick(View.java:2408)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.view.View$PerformClick.run(View.java:8816)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.os.Handler.handleCallback(Handler.java:587)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.os.Looper.loop(Looper.java:123)
07-05 18:01:27.158: E/AndroidRuntime(389):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-05 18:01:27.158: E/AndroidRuntime(389):  at java.lang.reflect.Method.invokeNative(Native Method)
07-05 18:01:27.158: E/AndroidRuntime(389):  at java.lang.reflect.Method.invoke(Method.java:521)
07-05 18:01:27.158: E/AndroidRuntime(389):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-05 18:01:27.158: E/AndroidRuntime(389):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-05 18:01:27.158: E/AndroidRuntime(389):  at dalvik.system.NativeStart.main(Native Method)

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:31:53+00:00Added an answer on June 7, 2026 at 2:31 am

    try AlertDialog.Builder builder = new AlertDialog.Builder(yourActivityName.this); instead of AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.