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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:50:53+00:00 2026-06-01T08:50:53+00:00

this is for an Android application, I have an XML file that I would

  • 0

this is for an Android application, I have an XML file that I would like to read named ‘categories.xml’:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<categories>
  <category>
    <name>Simulator Commands</name>
    <id>1</id>
  </category>
  <category>
    <name>Control Surface Commands</name>
    <id>2</id>
  </category>
  <category>
    <name>Control Surface Commands</name>
    <id>3</id>
  </category>
  <category>
    <name>General Aircraft Commands</name>
    <id>4</id>
  </category>
  <category>
    <name>Light Commands</name>
    <id>5</id>
  </category>
  <category>
    <name>Radio Commands</name>
    <id>6</id>
  </category>
  <category>
    <name>Autopilot Commands</name>
    <id>7</id>
  </category>
  <category>
    <name>Intrument Commands</name>
    <id>8</id>
  </category>
  <category>
    <name>View Commands</name>
    <id>9</id>
  </category>
  <category>
    <name>Slew Keys</name>
    <id>10</id>
  </category>
  <category>
    <name>Mission Commands</name>
    <id>11</id>
  </category>
  <category>
    <name>Multiplayer Commands</name>
    <id>12</id>
  </category>
  <category>
    <name>C172 Intrument Panels</name>
    <id>13</id>
  </category>
  <category>
    <name>BE58 Intrument Panels</name>
    <id>14</id>
  </category>
</categories>

And I would like to add the text from tag to an ArrayList named ‘categorys’. I’ve tried this:

ArrayList<String> categorys = new ArrayList<String>();
        categorys.add("Please select a category");
        //START ADDING HERE
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        File file = new File(Environment.getExternalStorageDirectory()+ "/fsx_kneeboard/categories.xml");
        FileInputStream fis = new FileInputStream(file);
        parser.setInput(new InputStreamReader(fis));
        parser.next();
        int eventType = parser.getEventType();
        int Categories = 0;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                Categories++;
            } if (eventType == XmlPullParser.START_TAG && Categories == 1) {
                Categories++;
            } if (eventType == XmlPullParser.START_TAG && Categories == 2) {
                categorys.add(parser.getText());
            }
            parser.next();
        }

But something in this part:

while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_TAG) {
                    Categories++;
                } if (eventType == XmlPullParser.START_TAG && Categories == 1) {
                    Categories++;
                } if (eventType == XmlPullParser.START_TAG && Categories == 2 && parser.getName.equals("name")) {
                    categorys.add(parser.getText());
                }
                parser.next();
            }

Make it force close, I’m sure it’s this part the error is in because if I remove it it will not force close and will only add “Please select a command” to the ArrayList.

Thanks for your time and help, zeokila

  • 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-01T08:50:54+00:00Added an answer on June 1, 2026 at 8:50 am

    The key is going to be this line…

        int eventType = parser.getEventType();
    

    …because it is outside the while {...} loop and it is never changing.

    That means the while condition eventType != XmlPullParser.END_DOCUMENT will never be false so you end up repeatedly calling parser.next() forcing it to past end-of-file probably causing an exception.

        int eventType = parser.getEventType();
        int Categories = 0;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                Categories++;
            } if (eventType == XmlPullParser.START_TAG && Categories == 1) {
                Categories++;
            } if (eventType == XmlPullParser.START_TAG && Categories == 2) {
                categorys.add(parser.getText());
            }
            parser.next();
        }
    

    You need to update eventType after each call to parser.next() and I suspect you’d also want to reset Categories to 0 after each call to categorys.add(...)

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

Sidebar

Related Questions

I have a Web Service and an Android application that uses this web service.
I am developing one application in android. In this I have to login into
I have to develop an application for an Android Tablet. This will do the
I have an android application that I'm developing, and the application really just a
I have an Android application that installs a database (~2000 rows across all tables)
I would like to build two versions of my Android application using an Apache
I am writing an Android application that interfaces with a RESTful service. This web
I have an android application that uses a datastructure consisting couple of binary trees
I have an android application that has a button which I want to have
I have a text file i want to include in my Android application, it

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.