Solved

java.lang.NullPoihterException

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

749 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