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 8702657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:42:29+00:00 2026-06-13T02:42:29+00:00

I have two tabs hosted in my Main Activity (I use ActionBarSherlock). My fragments

  • 0

I have two tabs hosted in my Main Activity (I use ActionBarSherlock).
My fragments load and parse a distant xml to populate the listview.

If I change the device orientation when fragment is fully loaded, it loads again without problem with the new orientation.
But if I change it while the fragment is loading, the app force closes at the completion of loading.

Am I doing something wrong?

public class PartOne extends SherlockListFragment{

// All static variables
    static final String URL = "http://Y.xml";
    // XML node keys
    static final String KEY_ITEM = "item"; // parent node
    static final String KEY_TITLE = "title";
    static final String KEY_CAT = "category";
    static final String KEY_DESC = "description";


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new BackgroundAsyncTask().execute();
    }

    public class BackgroundAsyncTask extends AsyncTask<String, String, ArrayList<HashMap<String, String>>> {

        @Override
        protected void onPreExecute() {
        }

        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(String... paths) {

            ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

            XMLParser parser = new XMLParser();
            String xml = parser.getXmlFromUrl(URL); // getting XML

            if (xml != null) {
            Document doc = parser.getDomElement(xml); // getting DOM element

            NodeList nl = doc.getElementsByTagName(KEY_ITEM);
            // looping through all item nodes <item>
            for (int i = 0; i < nl.getLength(); i++) {
                if(i%2 != 1) {
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) nl.item(i);

                // data to string (to modify them)
                String titre = parser.getValue(e, KEY_TITLE);
                String categorie = parser.getValue(e, KEY_CAT);           
                String description = parser.getValue(e, KEY_DESC);

                // adding each child node to HashMap key => value       
                map.put(KEY_TITLE, titre);
                map.put(KEY_CAT, categorie);
                map.put(KEY_DESC, description);

                // adding HashList to ArrayList
                menuItems.add(map);

                                    }       
                                                            }
                            }
            // selecting single ListView item
            ListView lv = getListView();

            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem
                    String name = ((TextView) view.findViewById(R.id.title)).getText().toString();
                    String cost = ((TextView) view.findViewById(R.id.categ)).getText().toString();
                    String description = ((TextView) view.findViewById(R.id.desciption)).getText().toString();
                    // Starting new intent
                    Intent in = new Intent(view.getContext(), SingleMenuItemActivity.class);
                    in.putExtra(KEY_TITLE, name);
                    in.putExtra(KEY_CAT, cost);
                    in.putExtra(KEY_DESC, description);
                    startActivity(in);

                }
            });
            return menuItems;
                                                                                    }

        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

            ListAdapter adapter = new SimpleAdapter(getActivity(),
                    result, R.layout.list_item,
                    new String[] {KEY_TITLE, KEY_DESC, KEY_CAT},
                    new int[] {R.id.title, R.id.desciption, R.id.categ});
            setListAdapter(adapter);
        }

    }

Log :

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
  • 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-13T02:42:31+00:00Added an answer on June 13, 2026 at 2:42 am

    Handle your task in onConfigurationChanged (Configuration newConfig) mothod,
    something like this

        Thread th=null;
        public void onCreate(bundle savedInstanceState)
        {
          //Initialize layout
    
          if(th==null) //This is to check whether task is running
           { 
          //Assign your task
          th=new Thread();
          th.start();
           }
        } 
    
        //handle the same here
        public void onConfigurationChanged (Configuration newConfig)
        {
    
           //Do the  layout changes
           if(th==null)//This is to check whether task is running
           { 
           //Assign your task
           th=new Thread();
           th.start();
           }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tabhost with two tabs. Each tab has his own activity. My
I have a launcher activity which contains two tabs which corresponds to two separate
I have two tabs. In these two tabs I have different activity groups. How
I have created two tabs in my Activity using the below code. This is
I have two listview in two tabs. I want to show only played videos
I have following problem: I have one activity in which I have two tabs
I am making a activity using Tab-Host. I have two tabs. When I start
I have Two Tabs Tab-1 and Tab-2 at bottom of the screen. Send button
In tab container let say I have two tabs [Tab1 & Tab2] Tab1 has
I have a page with two tabs that I want to be able to

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.