Solved

java.lang.NullPoihterException

Posted on 2008-10-14
3
213 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java. Convert method from recursion based to iteration based ( loop based ) 6 76
get weblogic logged in user in java 2 58
Java Loop 6 49
session migration servlets 2 26
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now