Kris
Kris

Reputation: 3769

Android: AsyncTask force closes

I have an asynctask that parses an xml file from the net. I'm storing its value to a variable of the main activity. When I run the following code, it force closes.

private class parseXMLAsync extends AsyncTask <String, String, String>{

    protected void onPreExecute(){
        super.onPreExecute();
        showDialog(PARSE_XML);
    }

    @Override
    protected String doInBackground(String... strings) {

        try{
            Engagia.this.url.openConnection();
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            ExampleHandler myExampleHandler = new ExampleHandler();
            xr.setContentHandler(myExampleHandler);
            xr.parse(new InputSource(Engagia.this.url.openStream()));

            List<ParsedExampleDataSet> parsedExampleDataSet = myExampleHandler.getParsedData();

            Iterator i;
            i = parsedExampleDataSet.iterator();
            ParsedExampleDataSet dataItem;

            while(i.hasNext()){
                    dataItem = (ParsedExampleDataSet) i.next();
                    String folder = dataItem.getParentTag();


                    if( folder == "Videos"  ){

                        MainAct.this.videoNames[MainAct.this.videoCount] = dataItem.getName();

                        MainAct.this.videoCount++;
                    }

            }

        }catch(Exception e){
            Log.e(LOG_TAG, e.getMessage());
        }
        return null;
    }

    @Override
    protected void onPostExecute(String lenghtOfFile) {
        if( mProgressDialog.isShowing() ){
            dismissDialog(PARSE_XML);
        }

        String str_contents = null;

        PopIt("Parsing Done", "STR CONTENTS >> " + str_contents, "Denied");
    }
}

The logcat says:

enter image description here

Upvotes: 0

Views: 295

Answers (1)

Alex Gitelman
Alex Gitelman

Reputation: 24722

Your exception does not seem to have a message. So it sends null to logger and logger does not like it. You can send e.toString() instead.

Upvotes: 1

Related Questions