Solved

java.lang.NullPoihterException

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

747 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

12 Experts available now in Live!

Get 1:1 Help Now