Note that there are some explanatory texts on larger screens.

plurals
  1. POOrientation change makes App crash (if done while loading SherlockFragment)
    text
    copied!<p>I have two tabs hosted in my Main Activity (I use ActionBarSherlock). My fragments load and parse a distant xml to populate the listview.</p> <p>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.</p> <p>Am I doing something wrong?</p> <pre><code>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&lt;String, String, ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; { @Override protected void onPreExecute() { } @Override protected ArrayList&lt;HashMap&lt;String, String&gt;&gt; doInBackground(String... paths) { ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); 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 &lt;item&gt; for (int i = 0; i &lt; nl.getLength(); i++) { if(i%2 != 1) { // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); 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 =&gt; 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&lt;?&gt; 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&lt;HashMap&lt;String, String&gt;&gt; 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); } } </code></pre> <p>Log :</p> <pre><code>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) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload