Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » XML import in RCP(Trouble faced during importing data from XML)
XML import in RCP [message #693043] Tue, 05 July 2011 16:57 Go to next message
Rajendra Kolli is currently offline Rajendra KolliFriend
Messages: 9
Registered: July 2011
Junior Member
Hi all,
I am new to Eclipse development. So I don't know whether it is proper to post this here. But here is the trouble I am facing,

I need to import data into an object and add the object to a list. I am using the following code,


SSAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

DefaultHandler handler = new DefaultHandler() {
private InstallerFeature tempFeature;
private StringBuilder description;

public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
if (qName.equalsIgnoreCase("FEATURE")) {
String test = attributes.getValue("id");
//System.out.println(test);
tempFeature.setPackageName("cdt");
tempFeature.setTitleName("cdt");
//System.out.println(tempFeature.getTitleName());
tempFeature.setVersonNumber(attributes.getValue("version"));
tempFeature.setImagePath(attributes.getValue("impath"));
} else if (qName.equalsIgnoreCase("DESCRIPTION")) {
description = new StringBuilder();
}

}

public void endElement(String uri, String localName,
String qName) throws SAXException {
if (qName.equalsIgnoreCase("FEATURE")) {
features.add(tempFeature);
tempFeature = null;
}
if (qName.equalsIgnoreCase("DESCRIPTION")) {
tempFeature.setDescriptionContent(description.toString());
}
}

public void characters(char ch[], int start, int length)
throws SAXException {
if (description == null)
return;
description.append(String.valueOf(ch, start, length));
}

The object temp feature is defined as an InstallerFeature as below


public class InstallerFeature {

private String packageName;
private String titleName;
private String versonNumber;
private String imagePath;
private String descriptionContent;

public void setPackageName(String packageName) {
this.packageName = packageName;
}

public String getPackageName() {
return packageName;
}

public void setTitleName(String titleName) {
System.out.println("Code is being called here");
this.titleName = titleName;
}

public String getTitleName() {
return titleName;
}

public void setVersonNumber(String versonNumber) {
this.versonNumber = versonNumber;
}

public String getVersonNumber() {
return versonNumber;
}

public void setDescriptionContent(String descriptionContent) {
this.descriptionContent = descriptionContent;
}

public String getDescriptionContent() {
return descriptionContent;
}

public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}

public String getImagePath() {
return imagePath;
}

}

When I run the code I am getting the following error

java.lang.NullPointerException
at ca.rokc.ide4edu.installer.Activator$1.startElement(Activator.java:120)

which points to the tempFeature.setPackageName() line in the importing code. I couldn't understand what to do. Please help
Re: XML import in RCP [message #693055 is a reply to message #693043] Tue, 05 July 2011 17:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
What code are you expecting will set tempFeature to a non-null value?
You've shown no code that does that...


> Hi all,
> I am new to Eclipse development. So I don't know whether it is proper
> to post this here. But here is the trouble I am facing,
>
> I need to import data into an object and add the object to a list. I
> am using the following code,
>
>
> SSAXParserFactory factory = SAXParserFactory.newInstance();
> SAXParser saxParser = factory.newSAXParser();
>
> DefaultHandler handler = new DefaultHandler() {
> private InstallerFeature tempFeature;
> private StringBuilder description;
>
> public void startElement(String uri, String localName,
> String qName, Attributes attributes)
> throws SAXException {
> if (qName.equalsIgnoreCase("FEATURE")) {
> String test = attributes.getValue("id");
> //System.out.println(test);
> tempFeature.setPackageName("cdt");
> tempFeature.setTitleName("cdt");
> //System.out.println(tempFeature.getTitleName());
>
> tempFeature.setVersonNumber(attributes.getValue("version"));
>
> tempFeature.setImagePath(attributes.getValue("impath"));
> } else if (qName.equalsIgnoreCase("DESCRIPTION")) {
> description = new StringBuilder();
> }
>
> }
>
> public void endElement(String uri, String localName,
> String qName) throws SAXException {
> if (qName.equalsIgnoreCase("FEATURE")) {
> features.add(tempFeature);
> tempFeature = null;
> }
> if (qName.equalsIgnoreCase("DESCRIPTION")) {
>
> tempFeature.setDescriptionContent(description.toString());
> }
> }
>
> public void characters(char ch[], int start, int length)
> throws SAXException {
> if (description == null)
> return;
> description.append(String.valueOf(ch, start,
> length));
> }
>
> The object temp feature is defined as an InstallerFeature as below
>
>
> public class InstallerFeature {
>
> private String packageName;
> private String titleName;
> private String versonNumber;
> private String imagePath;
> private String descriptionContent;
>
> public void setPackageName(String packageName) {
> this.packageName = packageName;
> }
>
> public String getPackageName() {
> return packageName;
> }
>
> public void setTitleName(String titleName) {
> System.out.println("Code is being called here");
> this.titleName = titleName;
> }
>
> public String getTitleName() {
> return titleName;
> }
>
> public void setVersonNumber(String versonNumber) {
> this.versonNumber = versonNumber;
> }
>
> public String getVersonNumber() {
> return versonNumber;
> }
>
> public void setDescriptionContent(String descriptionContent) {
> this.descriptionContent = descriptionContent;
> }
>
> public String getDescriptionContent() {
> return descriptionContent;
> }
>
> public void setImagePath(String imagePath) {
> this.imagePath = imagePath;
> }
>
> public String getImagePath() {
> return imagePath;
> }
>
> }
>
> When I run the code I am getting the following error
>
> java.lang.NullPointerException
> at
> ca.rokc.ide4edu.installer.Activator$1.startElement(Activator.java:120)
>
> which points to the tempFeature.setPackageName() line in the importing
> code. I couldn't understand what to do. Please help
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XML import in RCP [message #693169 is a reply to message #693055] Tue, 05 July 2011 23:59 Go to previous message
Rajendra Kolli is currently offline Rajendra KolliFriend
Messages: 9
Registered: July 2011
Junior Member
HI Ed Merks,
Thanks for your reply. I understood what you have asked. I defined a constructor method in InstallerFeature and when need i called it as

tempFeature = new InstallerFeature();

That solved that NullPointerException.

Thanks for pointing me at the exact issue in the code
Previous Topic:Unable to locate installable unit org.eclipse.ui.views
Next Topic:get eclipse runtime idle time
Goto Forum:
  


Current Time: Thu Apr 25 09:30:57 GMT 2024

Powered by FUDForum. Page generated in 0.03289 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top