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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:52:22+00:00 2026-06-12T11:52:22+00:00

hello guys i develop a simple app that read an XML file from the

  • 0

hello guys i develop a simple app that read an XML file from the internet by using the SAX but i get this error on logcat any help could be helpful

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reaf.xml"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
    android:name="com.read.xml.DataHandler"
    android:label="@string/title_activity_main" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".MainActivity" >
</activity>
</application>
</manifest>

Logcat

      10-06 08:29:52.204: D/AndroidRuntime(614): Shutting down VM
      10-06 08:29:52.204: W/dalvikvm(614): threadid=1: thread exiting with uncaught  exception (group=0x40015560)
      10-06 08:29:52.254: E/AndroidRuntime(614): FATAL EXCEPTION: main
      10-06 08:29:52.254: E/AndroidRuntime(614): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.read.xml/com.read.xml.DataHandler}:  java.lang.ClassCastException: com.read.xml.DataHandler
     10-06 08:29:52.254: E/AndroidRuntime(614):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
      10-06 08:29:52.254: E/AndroidRuntime(614):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
       10-06 08:29:52.254: E/AndroidRuntime(614):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
     10-06 08:29:52.254: E/AndroidRuntime(614):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
       10-06 08:29:52.254: E/AndroidRuntime(614):   at android.os.Handler.dispatchMessage(Handler.java:99)
      10-06 08:29:52.254: E/AndroidRuntime(614):    at android.os.Looper.loop(Looper.java:123)
     10-06 08:29:52.254: E/AndroidRuntime(614):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    10-06 08:29:52.254: E/AndroidRuntime(614):  at java.lang.reflect.Method.invokeNative(Native Method)
    10-06 08:29:52.254: E/AndroidRuntime(614):  at java.lang.reflect.Method.invoke(Method.java:507)
   10-06 08:29:52.254: E/AndroidRuntime(614):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    10-06 08:29:52.254: E/AndroidRuntime(614):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

10-06 08:29:52.254: E/AndroidRuntime(614): at dalvik.system.NativeStart.main(Native Method)
10-06 08:29:52.254: E/AndroidRuntime(614): Caused by: java.lang.ClassCastException: com.read.xml.DataHandler
10-06 08:29:52.254: E/AndroidRuntime(614): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-06 08:29:52.254: E/AndroidRuntime(614): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
10-06 08:29:52.254: E/AndroidRuntime(614): … 11 more
10-06 08:29:54.514: I/Process(614): Sending signal. PID: 614 SIG: 9

and this is the Datahandler class

               package com.read.xml;

  import java.io.BufferedReader;
  import java.io.IOException;
   import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
     import java.util.ArrayList;

  import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;

   import org.xml.sax.Attributes;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;

  import android.content.Context;
  import android.graphics.Color;
 import android.util.Log;
 import android.widget.TextView;

   public class DataHandler extends DefaultHandler {

//list for imported product data
private ArrayList<TextView> theViews;
//string to track each entry
private String currBrand = "";
//flag to keep track of XML processing
private boolean isProduct = false;
//context for user interface
private Context theContext;
//constructor
public DataHandler(Context cont) {
    super();
    theViews = new ArrayList<TextView>();
    theContext = cont;
 }
//start of the XML document
public void startDocument ()
{ Log.i("DataHandler", "Start of XML document"); }

//end of the XML document
public void endDocument ()
{ Log.i("DataHandler", "End of XML document"); }

//opening element tag
public void startElement (String uri, String name, String qName, Attributes atts)
{
    //find out if the element is a brand
    if(qName.equals("brand"))
    {
        //set product tag to false
        isProduct = false;
        //create View item for brand display
        TextView brandView = new TextView(theContext);
        brandView.setTextColor(Color.rgb(73, 136, 83));
        //add the attribute value to the displayed text
        String viewText = "Items from " + atts.getValue("name") + ":";
        brandView.setText(viewText);
        //add the new view to the list
        theViews.add(brandView);
    }
    //the element is a product
    else if(qName.equals("product"))
        isProduct = true;
}

//closing element tag
public void endElement (String uri, String name, String qName)
{
    if(qName.equals("brand"))
    {
        //create a View item for the products
        TextView productView = new TextView(theContext);
        productView.setTextColor(Color.rgb(192, 199, 95));
        //display the compiled items
        productView.setText(currBrand);
        //add to the list
        theViews.add(productView);
        //reset the variable for future items
        currBrand = "";
    }
}

//element content
public void characters (char ch[], int start, int length)
{
    //string to store the character content
    String currText = "";
    //loop through the character array
    for (int i=start; i<start+length; i++)
    {
        switch (ch[i]) {
        case '\\':
            break;
        case '"':
            break;
        case '\n':
            break;
        case '\r':
            break;
        case '\t':
            break;
        default:
            currText += ch[i];
            break;
        }
    }
    //prepare for the next item
    if(isProduct && currText.length()>0)
        currBrand += currText+"\n";
}

public ArrayList<TextView> getData()
{
    //take care of SAX, input and parsing errors
    try
    {
            //set the parsing driver
        System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
            //create a parser
        SAXParserFactory parseFactory = SAXParserFactory.newInstance();
        SAXParser xmlParser = parseFactory.newSAXParser();
            //get an XML reader
        XMLReader xmlIn = xmlParser.getXMLReader();
            //instruct the app to use this object as the handler
        xmlIn.setContentHandler(this);
            //provide the name and location of the XML file
        URL xmlURL = new URL("www.data-online.bugs3.com/public_html/test.xml");
            //open the connection and get an input stream
        URLConnection xmlConn = xmlURL.openConnection();
        InputStreamReader xmlStream = new    
           InputStreamReader(xmlConn.getInputStream());
            //build a buffered reader
        BufferedReader xmlBuff = new BufferedReader(xmlStream);
            //parse the data
        xmlIn.parse(new InputSource(xmlBuff));
    }
    catch(SAXException se) { Log.e("AndroidTestsActivity", 
            "SAX Error " + se.getMessage()); }
    catch(IOException ie) { Log.e("AndroidTestsActivity", 
            "Input Error " + ie.getMessage()); }
    catch(Exception oe) { Log.e("AndroidTestsActivity", 
            "Unspecified Error " + oe.getMessage()); }
        //return the parsed product list
    return theViews;
}


 }

i did not know what is the error

please help

  • 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-12T11:52:23+00:00Added an answer on June 12, 2026 at 11:52 am

    Where do you call DataHandler.getData? If this is in an activity constructor or on create call this will lead to a NetworkOnMainThreadException.

    If this is the case please look into AsyncTask: http://developer.android.com/reference/android/os/AsyncTask.html

    You would need to call getData in doInBackground.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello guys i develop a simple app that read an XML file from the
Hello guys. I think it isn't possible just using PHP, but just to be
hello guys I am trying to extract all the anchor links from aol but
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Hello guys I'm using C and GTK+ 2 I want to make a simple
hello guys simple question that i seemed to be stumped on. I have something
Hello guys for example when I open with notepad a text file it's shows
Hello guys I can't provide the code but you can see it on the
Hello guys i try to get an object global/persistent over more than one php
Hello guys I need to pass a string array over to a setter that

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.