Solved

java.lang.NullPoihterException

Posted on 2008-10-14
3
216 Views
Last Modified: 2013-11-23
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
Comment
Question by:newbieal
3 Comments
 
LVL 20

Accepted Solution

by:
Venabili earned 500 total points
ID: 22714571
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
 
LVL 1

Expert Comment

by:waleed hassan
ID: 22714747
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
 
LVL 4

Author Comment

by:newbieal
ID: 22721429
Thanks, db was not initialized - that was the issue.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 83
Why my table column Id is not passed to java object? 4 44
spring jars download 1 35
Html Table Looping (part 2) 5 27
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question