Solved

java.lang.NullPoihterException

Posted on 2008-10-14
3
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 34
Better way to make a string with template variables in java 3 53
jmeter usage 4 66
Setup Eclipse for Andriod development 2 20
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

751 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