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

  • Home
  • SEARCH
  • 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 7174277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:00:07+00:00 2026-05-28T16:00:07+00:00

I’m learning android now, and i write some simple codes according to the book.

  • 0

I’m learning android now, and i write some simple codes according to the book.

i create an android project named Chapter03_ResourceActivity, then create test.xml in res/xml/ folder, contents are as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <customer name = "first_name" age = "1" email = "first_name@xml.com" />
    <customer name = "second_name" age = "2" email = "second_name@xml.com" />
</resources>

and type codes in Chapter03_ResourceActivity.java(src/com.app.MainActivity/Chapter03_ResourceActivity.java) as follows:

package com.app.MainActivity;

import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Chapter03_ResourceActivity extends Activity {
    /** Called when the activity is first created. */

    private Button myButton;
    private TextView myTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button myButton = (Button)findViewById(R.id.btn_xml);
        final TextView myTextView = (TextView)findViewById(R.id.text_xml);

        myButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            StringBuilder sb = new StringBuilder();
            XmlResourceParser xrp = getResources().getXml(R.xml.test);
            int counter = 0;
            try {
                while(xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
                    if(xrp.getEventType() == XmlResourceParser.START_TAG) {
                        String name = xrp.getName();
                        if(name.equals("customer")) {
                            counter ++;
                            sb.append(counter + " Customer" + "\n");
                            sb.append(xrp.getAttributeValue(0) + "\n");
                            sb.append(xrp.getAttributeValue(1) + "\n");
                            sb.append(xrp.getAttributeValue(2) + "\n\n");
                        } 
                        xrp.next();
                    }
                } 
            myTextView.setText(sb.toString());    <<--Here Eclipse mark an error. 
                catch(XmlPullParserException e) {
                    e.printStackTrace();
                }
            }   
            }
        });           <<--Here Eclipse mark another error.
    }
}

Two errors have been marked in the code. i tried to solve it by myself, but forgive my dull, i cannot find it. i counted the number of “{” and “}” for many times, and just find they are right equal. Maybe i really miscounted? Or something i dont konw made this error? Any help appreciated.

  • 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-05-28T16:00:09+00:00Added an answer on May 28, 2026 at 4:00 pm
    catch(XmlPullParserException e) {
        e.printStackTrace();
    }
    

    should be:

    } catch(XmlPullParserException e) {
        e.printStackTrace();
    

    It’s not the quantity that’s causing you grief, just the placement. Your catch is actually inside the try block at the moment rather than immediately after it.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker

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.