You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Øyvind Vestavik <Oy...@idi.ntnu.no> on 2002/01/28 15:05:52 UTC

NullpointerException


I am passing a well formed xml document as a DOM document into a method
that is supposed to insert it into a dbxml database. But whenever i start
my program i get a java.lang.NullpointerExeption

I have found the line causing the trouble and it goes like this

XMLResource resource =
	(XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);

Anyone who could tell me what's wrong??

The whole class/method goes like:

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import org.w3c.dom.Document;
import java.io.*;

Public class AddDocument{

    public void add(Document doc) throws Exception{

	Collection col = null;
	try{

	    String driver = "org.dbxml.client.xmldb.DatabaseImpl";
	    Class c = Class.forName(driver);
	    Database database = (Database) c.newInstance();
	    DatabaseManager.getCollection("xmldb:dbxml:///db/REAP/Profiles");

	    String id = "test";

	    //this is the line where the exception is thrown:
	    XMLResource document =
                  (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);

	    document.setContentAsDom(doc); //doc is the received xml dom document
	    col.storeResource(document);

	}

	catch (XMLDBExeption e){
	    System.err.println("Error occured " + e.errorCode)
	}

	finally{
	    if (col !=null){
		col.close;
	    }
	}
    }
}

It would really help me if anyone of you knew what's wrong..

Thanks Øyvind

Øyvind Vestavik
Øvre Møllenberggt 44b
7014 Trondheim
oyvindve@idi.ntnu.no
41422911



RE: NullpointerException

Posted by Stéphane Nimsgern <sn...@otoobe.com>.
hi,

XMLResource.RESOURCE_TYPE might be null, the second parameter of
createResource
is a String representing a resource type. You can use as far as I know:
"XMLResource" and "BinaryResource".


-{-----Message d'origine-----
-{De : Øyvind Vestavik [mailto:Oyvind.Vestavik@idi.ntnu.no]
-{Envoyé : lundi 28 janvier 2002 15:06
-{À : xindice-users@xml.apache.org
-{Objet : NullpointerException
-{
-{
-{
-{
-{I am passing a well formed xml document as a DOM document into a method
-{that is supposed to insert it into a dbxml database. But whenever i start
-{my program i get a java.lang.NullpointerExeption
-{
-{I have found the line causing the trouble and it goes like this
-{
-{XMLResource resource =
-{	(XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
-{
-{Anyone who could tell me what's wrong??
-{
-{The whole class/method goes like:
-{
-{import org.xmldb.api.base.*;
-{import org.xmldb.api.modules.*;
-{import org.xmldb.api.*;
-{import org.w3c.dom.Document;
-{import java.io.*;
-{
-{Public class AddDocument{
-{
-{    public void add(Document doc) throws Exception{
-{
-{	Collection col = null;
-{	try{
-{
-{	    String driver = "org.dbxml.client.xmldb.DatabaseImpl";
-{	    Class c = Class.forName(driver);
-{	    Database database = (Database) c.newInstance();
-{
-{DatabaseManager.getCollection("xmldb:dbxml:///db/REAP/Profiles");
-{
-{	    String id = "test";
-{
-{	    //this is the line where the exception is thrown:
-{	    XMLResource document =
-{                  (XMLResource) col.createResource(id,
-{XMLResource.RESOURCE_TYPE);
-{
-{	    document.setContentAsDom(doc); //doc is the received
-{xml dom document
-{	    col.storeResource(document);
-{
-{	}
-{
-{	catch (XMLDBExeption e){
-{	    System.err.println("Error occured " + e.errorCode)
-{	}
-{
-{	finally{
-{	    if (col !=null){
-{		col.close;
-{	    }
-{	}
-{    }
-{}
-{
-{It would really help me if anyone of you knew what's wrong..
-{
-{Thanks Øyvind
-{
-{Øyvind Vestavik
-{Øvre Møllenberggt 44b
-{7014 Trondheim
-{oyvindve@idi.ntnu.no
-{41422911
-{
-{


Re: NullpointerException

Posted by Heinrich Götzger <go...@gmx.net>.
Øyvind,

your col equals null.

add 'col =' in line marked with 8-O. No offence ;-)

So long, hope it helps.


On Mon, 28 Jan 2002, Øyvind Vestavik wrote:

>
>
>I am passing a well formed xml document as a DOM document into a method
>that is supposed to insert it into a dbxml database. But whenever i start
>my program i get a java.lang.NullpointerExeption
>
>I have found the line causing the trouble and it goes like this
>
>XMLResource resource =
>	(XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
>
>Anyone who could tell me what's wrong??
>
>The whole class/method goes like:
>
>import org.xmldb.api.base.*;
>import org.xmldb.api.modules.*;
>import org.xmldb.api.*;
>import org.w3c.dom.Document;
>import java.io.*;
>
>Public class AddDocument{
>
>    public void add(Document doc) throws Exception{
>
>	Collection col = null;
>	try{
>
>	    String driver = "org.dbxml.client.xmldb.DatabaseImpl";
>	    Class c = Class.forName(driver);
>	    Database database = (Database) c.newInstance();
>	8-O
          DatabaseManager.getCollection("xmldb:dbxml:///db/REAP/Profiles");
>
>	    String id = "test";
>
>	    //this is the line where the exception is thrown:
>	    XMLResource document =
>                  (XMLResource) col.createResource(id, XMLResource.RESOURCE_TYPE);
>
>	    document.setContentAsDom(doc); //doc is the received xml dom document
>	    col.storeResource(document);
>
>	}
>
>	catch (XMLDBExeption e){
>	    System.err.println("Error occured " + e.errorCode)
>	}
>
>	finally{
>	    if (col !=null){
>		col.close;
>	    }
>	}
>    }
>}
>
>It would really help me if anyone of you knew what's wrong..
>
>Thanks Øyvind
>
>Øyvind Vestavik
>Øvre Møllenberggt 44b
>7014 Trondheim
>oyvindve@idi.ntnu.no
>41422911
>
>

regards

Heinrich
--
http://www.xmlBlaster.org