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

  • SEARCH
  • Home
  • 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 9227973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:12:40+00:00 2026-06-18T05:12:40+00:00

I’m having an issue with my onPostExecute from an AsyncTask class. Here is the

  • 0

I’m having an issue with my onPostExecute from an AsyncTask class. Here is the code.

–EDIT: added in the rest of the code by request–

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    preliminaryTasks();
}

private void preliminaryTasks() {

    //removed more code

    new discoverAddresses().execute();

}

public class discoverAddresses extends AsyncTask<String, Void, List<String>> {

    @Override
    protected List<String> doInBackground(String... params){

        /* Lots of code here taken out */

        List<String> addresses = new ArrayList<String>();
        //Added for debugging purposes
        addresses.add("http://192.168.1.120:80");
        addresses.add("http://192.168.1.110:80");
        return addresses;

    }

    @Override
    protected void onPostExecute(List<String> addresses){

        MainActivity.this.runOnUiThread(new Runnable(){
            public void run(){
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("Are you sure you want to exit?").setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                MainActivity.this.finish();
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage("Are you sure you want to exit?").setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        MainActivity.this.finish();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();

        return; 

    }
}
}

But the alert dialog never shows up; when I watch in the debugger it will execute the alert.show() line but it never displays on the UI. Does anyone have any ideas on why this is? Thanks!

EDIT: both AlertDialogs get executed in the debugger but never display on the UI

EDIT2: I copied just the code I posted here (to see if it was the removed code I took out for simplification that was causing the issue) into a new project and the alertdialog actually appears, meaning the code I took out is an issue. This is coming up in LogCat in my original project upon Force Close termination of the app.

02-02 11:13:28.746: D/AndroidRuntime(11658): Shutting down VM
02-02 11:13:28.746: W/dalvikvm(11658): threadid=1: thread exiting with uncaught exception (group=0x40fce300)
02-02 11:13:28.762: E/AndroidRuntime(11658): FATAL EXCEPTION: main
02-02 11:13:28.762: E/AndroidRuntime(11658): java.lang.NullPointerException
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.AbsListView.obtainView(AbsListView.java:2257)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.ListView.onMeasure(ListView.java:1156)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.View.measure(View.java:15172)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1077)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.Choreographer.doFrame(Choreographer.java:525)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.os.Handler.handleCallback(Handler.java:615)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.os.Looper.loop(Looper.java:137)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at android.app.ActivityThread.main(ActivityThread.java:4899)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at java.lang.reflect.Method.invokeNative(Native Method)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at java.lang.reflect.Method.invoke(Method.java:511)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
02-02 11:13:28.762: E/AndroidRuntime(11658):    at dalvik.system.NativeStart.main(Native Method)
  • 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-18T05:12:42+00:00Added an answer on June 18, 2026 at 5:12 am

    I found the problem with my code. At some point this method, promptAddresses was being called. It has its own separate AlertDialog. Because the addressArray had an index of 5 it was screwing with the AlertDialog.builder because three of the indexes were null.

    TLDR: Don’t have any null values in a string array when dealing with AlertDialog.Builders

    SOLUTION: final String[] addressArray = new String[addresses.size()];

    Thank you very much to everyone who helped. I apologize for not giving the full code and confusing the whole problem. At any rate, your answers still helped very much.

    public String promptAddresses(List<String> addresses){
        final String[] addressArray = new String[5];
        int i = 0;
    
        Iterator it = addresses.iterator();
        while(it.hasNext()){
            String next = (String) it.next();
            addressArray[i] = next;
            Log.i("ADDRESSES", next);
            i++;
        }
    
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("Pick your address");
        builder.setItems(addressArray, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                   // The 'which' argument contains the index position
                   // of the selected item
               }
        });
        AlertDialog alert =  builder.create();
        alert.show();
    
        return hubAddress;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.