XML import in RCP [message #693043] |
Tue, 05 July 2011 16:57 |
Rajendra Kolli 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 |
Ed Merks Messages: 33141 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/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02772 seconds