• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

java.lang.NullPoihterException

I have the following code snippet and am running into the java.lang.NullPointerException. Any ideas what the issue might be?
String fN = "afile.html";
 
File file = new File(fN);
	
		try {
			
			doc = db.parse ( file );
			
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
			
		}

Open in new window

0
newbieal
Asked:
newbieal
1 Solution
 
VenabiliCommented:
On which line?
Without this - make sure that db is initialised - most likely it is null (or the file is not found and the object file is null
0
 
waleed hassanCommented:
i think variable db is not initialized by using "new" for example
you should use the code above before you call the parse method :  
 
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// some code and then use 
 
doc = db.parse ( file ); // your line of code 

Open in new window

0
 
newbiealAuthor Commented:
Thanks, db was not initialized - that was the issue.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now