[jsword-devel] Books.installed() throws java.lang.ExceptionInInitializerError

Norbert Plött jsword-devel@crosswire.org
Thu, 1 Apr 2004 19:49:27 +0200


DM,

> Books does have a static method called installed().

that's right. I mixed up older and newer versions of jsword.jar. Now I found 
it.

> There is a race condition in the code and I am not sure how to fix it

I got the latest jsword.jar just now (April 1) and according to what Joe 
walker wrote

> Sorry to to reply earlier. I've changed the Book register process so 
> that the threading is optional, and defaults to single-threaded.
> I've also made it a 'Job' so you see progress in the GUI.
> This should stop the race conditions, I'll make sure it gets build to 
> the jnlp dir tonight.

this should include the patch he made.

I changed my demo code a little:

    public void readPlainText() throws BookException, NoSuchVerseException {
        System.out.println("readPlainText() started");
        try {
            System.out.println("Start readPlainText()");
            //        Defaults.setBibleByName("GerSch");
            Passage ref = PassageFactory.createPassage("Mat 1 1");
            Books books = Books.installed() ;
            BookMetaData meta = books.getBookMetaData("German Schlachter Bibel 
(1951)");
            Book bible = meta.getBook();
            BookData data = bible.getData(ref);
            String text = data.getPlainText();
            
            System.out.println("The plain text of Mat 1:1 is "+text);
        }
        catch (Exception ex) {
            System.out.println("Exception:" + ex.getMessage());
            StackTraceElement[] stel = ex.getStackTrace();
            for (int i=0; i<stel.length; i++) {
                System.out.println(stel[i].getClassName() + "." + 
stel[i].getMethodName() + " at "+ stel[i].getFileName() + " : " + 
stel[i].getLineNumber());
            }
        }
        System.out.println("readPlainText() ended");
    }

Below is the console output. The call to Books.installed() throws the 
exception:

readPlainText() started
Start readPlainText()
log4j:WARN No appenders could be found for logger 
(org.crosswire.jsword.passage.PassageUtil).
log4j:WARN Please initialize the log4j system properly.
java.lang.ExceptionInInitializerError
        at org.crosswire.jsword.book.Books
$RegisterRunnable.run(Books.java:359)
        at org.crosswire.jsword.book.Books.<clinit>(Books.java:345)
        at 
de.nops.BibleStat.Gui.BibleStatGui.readPlainText(BibleStatGui.java:141)
        at 
de.nops.BibleStat.Gui.BibleStatGui.jMenuItemTestActionPerformed(BibleStatGui.java:94)
        at de.nops.BibleStat.Gui.BibleStatGui.access$200(BibleStatGui.java:35)
        at de.nops.BibleStat.Gui.BibleStatGui
$3.actionPerformed(BibleStatGui.java:77)
        at 
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton
(... more swing and awt stuff ...)
Caused by: java.lang.NullPointerException
        at org.crosswire.jsword.util.Project.<init>(Project.java:97)
        at org.crosswire.jsword.util.Project.<clinit>(Project.java:66)
        ... 37 more
  
What do I do next?

Bye

Norbert