User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » java help Page [1]  
psnarula
All American
1540 Posts
user info
edit post

I'm parsing XML using SAX for a class I'm taking at Johns Hopkins. The teacher gave us a class to extend. His class extends DefaultHandler. Here is his class:

public abstract class XMLLoaderBase extends DefaultHandler {

public abstract void endElement(String uri, String localName, String qName)
throws SAXException;

// other stuff...
}


His class has lots of stuff in it but the endElement method is all I care about right now. He's overriding this method from the DefaultHandler class.

My class extends his:

public class JobRequestXMLLoader extends XMLLoaderBase {

SimpleDateFormat sdf_;

public void endElement(String uri, String localName, String qName)
throws SAXException {

if (qName.equals("due-date")) {
date_ = sdf_.parse(text);
}
}
}


so basically whenever I see the end of the "due-date" tag, I want to turn the enclosed String (which I'm calling "text") into a java.util.Date by using the SimpleDateFormat.parse() method. The problem is that the parse method throws a ParseException. I can't add the ParseException to the endElement method signature because then I'm not overriding the abstract method from my instructor's class.

I tried adding the ParseException to endElement and then renaming the method "myEndElement" while also making another endElement method that just calls myEndElement but Eclipse complains that the myEndElement method has "Unhandled exception type ParseException". So how do I fix this?

2/24/2006 1:10:33 PM

DonMega
Save TWW
4202 Posts
user info
edit post

why don't you use a try/catch block and catch the exception instead of throwing it?

2/24/2006 1:15:42 PM

psnarula
All American
1540 Posts
user info
edit post

?

i've never really understood exceptions. i just know to add the exception to the end of the method declaration when eclipse complains about it...

2/24/2006 1:23:46 PM

psnarula
All American
1540 Posts
user info
edit post

sweet. i did this:


if (qName.equals("due-date")) {
try {
date_ = sdf_.parse(text);
jobRequest_.setDueDate(date_);
} catch (ParseException ex) {
ex.printStackTrace();
}


and it works great. thanks so much.

[Edited on February 24, 2006 at 1:27 PM. Reason : asdf ]

2/24/2006 1:26:39 PM

DonMega
Save TWW
4202 Posts
user info
edit post

no problem

2/24/2006 1:38:33 PM

 Message Boards » Tech Talk » java help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.