Note that there are some explanatory texts on larger screens.

plurals
  1. POcannot create handler inside thread that has not called looper.prepare()
    primarykey
    data
    text
    <p>I have an Activity in which i m getting the results from XML via Async task. This is my code of the activity from which i am getting the prediction</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_prediction); Past = (TextView) findViewById(R.id.textView1); Present = (TextView) findViewById(R.id.textView2); Future = (TextView) findViewById(R.id.textView3); new GetPrediction().execute(); } class GetPrediction extends AsyncTask &lt;Void, String, String&gt; { ProgressDialog dialog = new ProgressDialog(Prediction.this); @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); dialog.setMessage("Getting your fortune"); dialog.setCancelable(false); dialog.show(); } @Override protected String doInBackground(Void... b) { // TODO Auto-generated method stub try { URL website = new URL(baseUrl); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); HandlingXMLReading doingWork = new HandlingXMLReading(); // created object of default handler class xr.setContentHandler(doingWork); xr.parse(new InputSource(website.openStream())); past = doingWork.getPastPrediction(); present = doingWork.getPresentPrediction(); future = doingWork.getFuturePrediction(); } catch( Exception e) { past = e.getMessage(); present = e.getMessage(); future = e.getMessage(); } return past; } @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); dialog.dismiss(); Past.setText(result); Present.setText(present); Future.setText(future); } } } </code></pre> <p>Now this works fine, but the problem is when this Async task call the Default handler class It gives me the above error. In default handler class I made an object of a class from which I am getting some numbers. I am using that numbers to parse the XML. But when I removed That class object the code works fine. Here is the code of HandleXMLData.class</p> <pre><code>public class HandlingXMLReading extends DefaultHandler { // setting up the opbject XMLDataCollection prediction = new XMLDataCollection(); /*These next 4 lines gives the error of * cannot create the handler inside thread */ SelectionFuture CardNo = new SelectionFuture(); int PastCard = CardNo.pastCardNo; int PresentCard = CardNo.presentCardNo; int FutureCard = CardNo.FutureCardNo; /* Method Containing the Past Prediction*/ public String getPastPrediction() { return prediction.Past(); } /* Method Containing the Present Prediction*/ public String getPresentPrediction() { return prediction.Present(); } /* Method Containing the Past Prediction*/ public String getFuturePrediction() { return prediction.Future(); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // TODO Auto-generated method stub super.startElement(uri, localName, qName, attributes); if (localName.equals("overview_prediction1")){ String past = attributes.getValue("name"); prediction.setPast(past); } if (localName.equals("overview_prediction2")){ String present = attributes.getValue("name"); prediction.SetPresent(present); } if (localName.equals("overview_prediction3")){ String future = attributes.getValue("name"); prediction.SetFuture(future); } }} </code></pre> <p>I am not able to understand what is happening. Thanks In advance</p>
    singulars
    1. This table or related slice is empty.
    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.
    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