Skip to main content

Null Pointer Exception

3 replies [Last post]
Joined: 2005-07-15

I am using JAXB to parse my XML. The API generated from my XML schemas by using JAXB contains methods for all elements defined in Schemas. But XML data files that i am trying to parse does not contain all the elements at one time. I am performing the following check while populating the elements.

Example :

hasht.put("COUNTRY_CODE", (facd.getLocationAddress().getCountryIdentity().getCountryCode() == null || facd.getLocationAddress().getCountryIdentity().getCountryCode().length() == 0 ? spce : facd.getLocationAddress().getCountryIdentity().getCountryCode()) );

But it throws NullPointer Exception as it is not able to find the relevant data/tag "" in the XML file. Anybody knows how to resolve this.

Thanks for your Time and Help in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-09

I'm not sure what is the JAXB problem you are trying to point out. Just like any Java API, JAXB objects may return null from certain methods, and it's up to the caller to check for those.

It seems to me that this is an operator error, in the sense that you aren't checking null in your code where it could be null.

Or am I missing your point?

Joined: 2005-07-15

Getting a Null Pointer exception at the following line.

List repList = rep.getReportData().getReportValidation();

if (repList.size() > 0)
call method abc(repList, repKey);
call method xyz();

Error :

at Main.addReport(

at Main.addTriSubmission(

at Main.main(

Exception in thread "main" Process exited with exit code 1.

Reason :
The instance of XML data file that i am working with, does not contain the data type tags for the ReportDataType.
But the ReportDataType is defined in XML schemas used and future instances of xml file will contain this data.

Problem :
For now how to check for data type Tags (like ReportID etc) in XML data file (which are not available) in the parsing program that i am writing.

Hope this is clear enough.


Joined: 2003-06-09

I might be still missing your point, but isn't it just:[code]if(rep.getReportData()==null) {
// no report data to work with
} else {
List repList = rep.getReportData().getReportValidation();