Note that there are some explanatory texts on larger screens.

plurals
  1. POCaused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views
    primarykey
    data
    text
    <p>I am trying to write a program to parse the given xml. However, it throws that error message:"<strong>Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.</strong> " This is my code </p> <pre><code> package com.example.xmlparserdeneme; import java.io.IOException; import java.util.ArrayList; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.widget.ListView; public class MainActivity extends Activity { ArrayList&lt;String&gt; titles = new ArrayList&lt;String&gt;(); Context ctx = this; CustomAdapter adapter = null; ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((Activity) ctx).setContentView(R.layout.activity_main); new parseXML().execute(); Log.i("info2", titles.toString()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } class parseXML extends AsyncTask&lt;String, Void, String&gt; { MySaxHandler handler; @Override protected String doInBackground(String... params) { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = null; try { parser = spf.newSAXParser(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } handler = new MySaxHandler(); try { parser.parse( "/xmlParserDeneme/src/Database.xml", handler); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i("info", titles.toString()); return "a"; } @Override protected void onPostExecute(String result) { lv = (ListView) findViewById(R.id.listView); lv.setAdapter(new CustomAdapter(titles, ctx)); } public ArrayList&lt;String&gt; getArray() { return titles; } public class MySaxHandler extends DefaultHandler { StringBuffer chars; public void startElement(String uri, String localName, String qName, Attributes atts) { chars = new StringBuffer(); } public void endElement(String uri, String localName, String qName) throws SAXException { if (localName.equalsIgnoreCase("description")) titles.add(chars.toString()); } public void characters(char ch[], int start, int length) { chars.append(new String(ch, start, length)); } } } } </code></pre> <p>I am new at android, I don't know where to change. I'd be appreciated if anyone tell me how to fix it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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