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 Jonathan Melhuish <j....@signal.qinetiq.com> on 2004/04/21 19:29:12 UTC

Null Pointer Exception

In the following line in my Java program, col returns null:

XPathQueryService service = (XPathQueryService) 
col.getService("XPathQueryService","1.0");

*  This error is equivalent to the database not being present.
*  I have tried several known-good versions of the code and database; 
all fail with the same error.
*  I receive the same error with Xindice 1.0 and 1.1.
*  I have tested it under Windows and Linux (both with Tomcat 4.1.27), 
both produce the same error.
*  The xindice "UglyBrowser" allows me to successfully view my database 
through Tomcat.
*  The database table is currently in the default location of 
~/tomcat/webapps/xindice/WEB-INF/db
*  I have tried db.setProperty("db-home") using relative and absolute 
paths, to no avail

I'm starting to run out of ideas now!  :-(  Niggling questions include:

*  What broke?  I haven't changed Tomcat or Xindice 1.0 on my Linux box 
since it was working, whilst the Windows box is a "fresh" installation.
*  How come the UglyBrowser works, but my code doesn't?  My code used to 
work.

Any help or pointers would be very much appreciated!

Cheers,

Jon

PS:  Here's the code I'm using to connect to the database:
------------------------------
  public void connect() throws RepositoryException {
    try {
        Class driver = 
Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl");

        // initialize a new database, then register it globally
        Database db = (Database) driver.newInstance();
       
        
db.setProperty("db-home","/home/jon/tomcat/webapps/xindice/WEB-INF");
        db.setProperty("managed","true");
      
        DatabaseManager.registerDatabase(db);
        col = 
DatabaseManager.getCollection("xmldb:xindice-embed:///db/sne/");
        if (col==null) {
            throw new RepositoryException("Col is null!");
        }
  }
------------------------------

Re: Null Pointer Exception

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Jonathan Melhuish wrote:

> Vadim Gritsenko wrote:
>
>>> public void connect() throws RepositoryException {
>>>    try {
>>>        Class driver = 
>>> Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl");
>>
>>
>>
>> You are using embedded driver. This means, *database will be running 
>> within the JVM of this java program*.
>
>
> Okay.  I have xindice installed as a webapp under Tomcat.  From the 
> logs, it looks like Xindice is loading successfully with Tomcat.  Does 
> this mean that Xindice is "running in the same JVM"?  So the embedded 
> driver should work?


Not necessarily! If you have several webapps, one with Xindice, and one 
yours, they will be loaded using different ClassLoaders. This would make 
it impossible for embedded driver in managed mode in one webapp to 
access database mounted by XindiceServlet in another webapp.

It is possible to overcome this, you can move xindice and xmldb jars 
from the WEB-INF/lib to the tomcat's shared libraries. Then, all jar 
files will be loaded by same classloader, and embedded driver will work 
(I haven't tried, but it should work).



>>>        // initialize a new database, then register it globally
>>>        Database db = (Database) driver.newInstance();
>>>              
>>> db.setProperty("db-home","/home/jon/tomcat/webapps/xindice/WEB-INF");
>>
>>
>>
>>
>> Database, running within this JVM, will mount database files from the 
>> specified location.
>> IMPORTANT: You HAVE TO guarantee that no other process (no other JVM) 
>> accesses this database.
>
>
> Am I right in thinking that the db-home that I have set is actually 
> the default anyway?  It's also not massively clear from the 
> documentation I have read what this path is relative to (if it were 
> not absolute).


IIRC, yes, it defaults to WEB-INF. You can simply remove this line.



>>>        db.setProperty("managed","true");
>>
>>
>>
>> This means that driver will NOT start database automatically. You 
>> have to manually start the database, and manually manage database 
>> instance.
>
>
> I'm not sure I actually want managed mode in that case, so I set it to 
> false.


If you want your database started by XindiceServlet, you *do* want 
either managed driver (provided that you moved all jars as described 
above), or xmlrpc driver.


> Presumably I can still use DatabaseManager if my database is not 
> managed?  (you can see why I get confused!)


Yes, you can always use DatabaseManager.


> Also, could you just confirm that this property name is correct?  It 
> is copied from the UpgradeTo11EmbedNotes 
> <http://wiki.apache.org/xindice/UpgradeTo11EmbedNotes?action=fullsearch&value=UpgradeTo11EmbedNotes&literal=1&case=1&context=40> 
> Wiki page, but you refer to "PROP_XINDICE_MANAGED" in another post.  
> I've been reading lots of the Javadocs today, but can't find a 
> reference to the property names.


All property names are here (public static final String PROP_* and 
public static final String SYSPROP_*):
    
http://cvs.apache.org/viewcvs.cgi/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java?rev=1.26&view=auto
and here:
    
http://xml.apache.org/xindice/api/org/apache/xindice/client/xmldb/embed/DatabaseImpl.html



>>>             DatabaseManager.registerDatabase(db);
>>>        col = 
>>> DatabaseManager.getCollection("xmldb:xindice-embed:///db/sne/");
>>
>>
>>
>>
>> Because you asked for managed mode, and you have not started the 
>> database, this method will return null.
>
>
> Even with managed set to false, DatabaseManager.getCollection still 
> returns null.


I think I understood your config now; and explained this situation above.

Vadim


Re: Null Pointer Exception

Posted by Jonathan Melhuish <j....@signal.qinetiq.com>.
I'm really sorry to have to post yet again, but I'm really struggling to 
understand what I'm doing wrong!

Vadim Gritsenko wrote:

>> public void connect() throws RepositoryException {
>>    try {
>>        Class driver = 
>> Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl");
>
>
>
> You are using embedded driver. This means, *database will be running 
> within the JVM of this java program*.

Okay.  I have xindice installed as a webapp under Tomcat.  From the 
logs, it looks like Xindice is loading successfully with Tomcat.  Does 
this mean that Xindice is "running in the same JVM"?  So the embedded 
driver should work?

>>        // initialize a new database, then register it globally
>>        Database db = (Database) driver.newInstance();
>>              
>> db.setProperty("db-home","/home/jon/tomcat/webapps/xindice/WEB-INF");
>
>
>
> Database, running within this JVM, will mount database files from the 
> specified location.
> IMPORTANT: You HAVE TO guarantee that no other process (no other JVM) 
> accesses this database.

Am I right in thinking that the db-home that I have set is actually the 
default anyway?  It's also not massively clear from the documentation I 
have read what this path is relative to (if it were not absolute).

>
>>        db.setProperty("managed","true");
>
>
>
> This means that driver will NOT start database automatically. You have 
> to manually start the database, and manually manage database instance.

I'm not sure I actually want managed mode in that case, so I set it to 
false.  Presumably I can still use DatabaseManager if my database is not 
managed?  (you can see why I get confused!)

Also, could you just confirm that this property name is correct?  It is 
copied from the UpgradeTo11EmbedNotes 
<http://wiki.apache.org/xindice/UpgradeTo11EmbedNotes?action=fullsearch&value=UpgradeTo11EmbedNotes&literal=1&case=1&context=40> 
Wiki page, but you refer to "PROP_XINDICE_MANAGED" in another post.  
I've been reading lots of the Javadocs today, but can't find a reference 
to the property names.

>>             DatabaseManager.registerDatabase(db);
>>        col = 
>> DatabaseManager.getCollection("xmldb:xindice-embed:///db/sne/");
>
>
>
> Because you asked for managed mode, and you have not started the 
> database, this method will return null.

Even with managed set to false, DatabaseManager.getCollection still 
returns null.

I gather that this could mean that the Collection is not being found, 
however am I right to assume that this isn't the case, seeing as the 
UglyBrowser functions correctly?

Thanks very much for your help, I'll buy you a pint someday ;-)

Cheers,

Jon

Re: Null Pointer Exception

Posted by Vadim Gritsenko <va...@reverycodes.com>.
There are multiple issues here...

Jonathan Melhuish wrote:

> public void connect() throws RepositoryException {
>    try {
>        Class driver = 
> Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl");


You are using embedded driver. This means, *database will be running 
within the JVM of this java program*.


>        // initialize a new database, then register it globally
>        Database db = (Database) driver.newInstance();
>              
> db.setProperty("db-home","/home/jon/tomcat/webapps/xindice/WEB-INF");


Database, running within this JVM, will mount database files from the 
specified location.
IMPORTANT: You HAVE TO guarantee that no other process (no other JVM) 
accesses this database.


>        db.setProperty("managed","true");


This means that driver will NOT start database automatically. You have 
to manually start the database, and manually manage database instance.


>             DatabaseManager.registerDatabase(db);
>        col = 
> DatabaseManager.getCollection("xmldb:xindice-embed:///db/sne/");


Because you asked for managed mode, and you have not started the 
database, this method will return null.


Vadim



>        if (col==null) {
>            throw new RepositoryException("Col is null!");
>        }
>  }
> ------------------------------
>


Re: xindice 1.14b standalone

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Wojtek wrote:

>Hello,
>I read information from site:
>http://wiki.apache.org/xindice/InstallationBuiltInJetty
>I downloaded xindice 1.14b sources from:
>http://xml.apache.org/xindice/download.cgi
>I unpacked the tar.gz file and run build.sh.
>And I cannot find the xindice.sh file mentioned in wiki.
>
>My problem is: where is xindice.sh file? How to run command line xindice
>start ?
>Maybe that is silly question, but seriously, I cannot find how to start
>jetty and xindice 1.1 as a standalone.
>  
>

It seems that file have not made into the release... Please get one from 
the CVS:
    http://cvs.apache.org/viewcvs.cgi/xml-xindice/

Patch to contributor.xml (that's where dist creation script is) is 
welcome :-)

Vadim


Re: xindice 1.14b standalone

Posted by Wojtek <vi...@gazeta.pl>.
----- Original Message ----- 
From: "Wojtek" <vi...@gazeta.pl>
To: <xi...@xml.apache.org>
Sent: Thursday, April 22, 2004 8:06 PM
Subject: xindice 1.14b standalone


> Hello,
> I read information from site:
> http://wiki.apache.org/xindice/InstallationBuiltInJetty
> I downloaded xindice 1.14b sources from:
> http://xml.apache.org/xindice/download.cgi
> I unpacked the tar.gz file and run build.sh.
> And I cannot find the xindice.sh file mentioned in wiki.
> 
The solution is: download the latest CVS :)

Regards,
Wojtek



xindice 1.14b standalone

Posted by Wojtek <vi...@gazeta.pl>.
Hello,
I read information from site:
http://wiki.apache.org/xindice/InstallationBuiltInJetty
I downloaded xindice 1.14b sources from:
http://xml.apache.org/xindice/download.cgi
I unpacked the tar.gz file and run build.sh.
And I cannot find the xindice.sh file mentioned in wiki.

My problem is: where is xindice.sh file? How to run command line xindice
start ?
Maybe that is silly question, but seriously, I cannot find how to start
jetty and xindice 1.1 as a standalone.

Regards,
Wojtek