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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:54:51+00:00 2026-05-28T20:54:51+00:00

i create an android application. and typed some codes just like : public void

  • 0

i create an android application. and typed some codes just like :

public void onCreate(Bundle savedInstanceState) {
...
XmlResourceParser xrp = getResources().getXml(R.xml.OneXml);   <==OneXml is a custom xml file in folder res/xml
...
try {
    ....
    xrp.next();
    .... 
} catch(IOException e) {
        e.printStackTrace();
} catch(XmlPullParserException e) {
        e.printStackTrace();
} 
...

i found that i can neither delete catch(IOException e) nor catch(XmlPullParserException e), when i try to delete one of them, Eclipse marks an error at xrp.next() and tells me that Unhandled exception type IOException or Unhandled exception type XmlPullParserException, so must i add the two catch? why does Eclipse ask me to add two catch compulsively? Can’t the code be compiled successfully without the two catch?

  • 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-28T20:54:51+00:00Added an answer on May 28, 2026 at 8:54 pm

    Exception Handling ways:
    We can handle a ‘problem statement’ (Problem Statement is any statement which can throw an exception) in two ways.

    • Enclose the statement in try-catch block.
    • Append a throws clause in the method header.

    Handling Exception in Overridden Methods:
    If you are overriding a method in child class. Then you cannot append extra throws clause in its signature. In your case onCreate is a method in parent class, which is overridden in child class hence we can not append throws clause in it header. So you have to enclose any ‘Problem Statements’ within onCreate method in try-catch blocks.

    Examples:
    Enclose the statement in try-catch block.

    public void myMethod(){
            try{
                // Problem Statement
            }catch(IllegalAccessException e){
                e.printStackTrace();
            }catch(NullPointerException e){
                e.printStackTrace();
            }
        }
    

    Append a throws clause in the method header.

    public void myMethod()
            throws IllegalAccessException, NullPointerException{
                // Problem Statement
        }
    

    Examples Overridden Methods:
    Valid throws clause: A throws clause in overridden method is valid if it is also in parent’smethod.

    public class Parent {
        public int method() 
            throws IllegalAccessException,NullPointerException, Exception {
            return 0;
        }
    }
    public class child extends Parent {
        // throws is part of method because parent method
        // have throws clause
        @Override
        public int method() 
            throws IllegalAccessException, NullPointerException,
                Exception {
                //Problem Statement
            return super.method();
        }
    }
    

    Invalid throws clause: A throws clause in overridden method is invalid if it is not present in parent’s method.

    public class Parent {
        public int method(){
            return 0;
        }
    }
    
    public class child extends Parent {
        //**Error:** We can not append throws clause in the method because
        // parent method do not have a throws clause
        @Override
        public int method() 
            throws IllegalAccessException, NullPointerException,
                Exception {
                //Problem Statement
            return super.method();
        }
    }
    

    So we have to modify our child class’s method and remove throws clause as parent method do not contain throws clause in this particular situation. We have to handle exception through try-catch block.

    public class child extends Parent {
        //**Error:** We can not append throws clause in the method because
        // parent method do not have a throws clause
        @Override
        public int method() {
            try{
                // Problem Statement
            }catch(IllegalAccessException e){
                e.printStackTrace();
            }catch(NullPointerException e){
                e.printStackTrace();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to create an Android application that loops Audio from the
I am trying to create a simple Android application that has a ActivityList of
I want to create an application for Android that will be able to scan
If I create an application for Android, how do you package extra items in
For Android GUI: I would like to create a window that I can pull
Hi. I have create a background service application following this tutorial http://androidsourcecode.blogspot.com/2010/10/basic-android-background-service.html . But
I am trying to create a JSON String in the Android application. JSONArray jArrayFacebookData
I am a new to Android development and I would like to create an
In my android application I want to create a custom type of IM that
I am new to android. I just created a simple application using Aynctask. Basically,

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.