Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9312 > unrolled thread

ExceptionInInitializerError

Started byNovice <novice@example..com>
First post2011-10-30 13:57 +0000
Last post2011-10-31 01:28 -0700
Articles 7 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  ExceptionInInitializerError Novice <novice@example..com> - 2011-10-30 13:57 +0000
    Re: ExceptionInInitializerError "John B. Matthews" <nospam@nospam.invalid> - 2011-10-30 10:07 -0400
      Re: ExceptionInInitializerError Novice <novice@example..com> - 2011-10-30 15:14 +0000
        Re: ExceptionInInitializerError Stanimir Stamenkov <s7an10@netscape.net> - 2011-10-30 17:52 +0200
        Re: ExceptionInInitializerError Lew <lewbloch@gmail.com> - 2011-10-30 08:45 -0700
        Re: ExceptionInInitializerError Roedy Green <see_website@mindprod.com.invalid> - 2011-10-30 23:57 -0700
        Re: ExceptionInInitializerError Roedy Green <see_website@mindprod.com.invalid> - 2011-10-31 01:28 -0700

#9312 — ExceptionInInitializerError

FromNovice <novice@example..com>
Date2011-10-30 13:57 +0000
SubjectExceptionInInitializerError
Message-ID<Xns9F8E6573E3F9Fjpnasty@94.75.214.39>
I'm getting an unexpected runtime error when I execute my applet on a 
webpage from a jar. I should note that I do NOT get this same error when I 
run this same applet in Eclipse, either as an applet or as application 
using Roedy Green's "Hybrid/switchhitter" technique.

This is the line that it doesn't like: 

       switch(FooConstants.DESIRED_FORMAT) {

The relevant line of FooConstants is: 

    public static final Formats DESIRED_FORMAT = Formats.PARAGRAPH_FORMAT;

And Format is defined as follows:

public enum Formats {

    /** Bulleted list. */ 
    LIST_FORMAT, 
    
    /** Paragraph. */
    PARAGRAPH_FORMAT
}


Can anyone tell me why I'm getting this error? Also, I'm curious to know 
why this error doesn't occur when I run the applet in Eclipse. 

-- 
Novice

[toc] | [next] | [standalone]


#9313

From"John B. Matthews" <nospam@nospam.invalid>
Date2011-10-30 10:07 -0400
Message-ID<nospam-7ED1EB.10073030102011@news.aioe.org>
In reply to#9312
In article <Xns9F8E6573E3F9Fjpnasty@94.75.214.39>,
 Novice <novice@example..com> wrote:

> I'm getting an unexpected runtime error when I execute my applet on a 
> webpage from a jar. I should note that I do NOT get this same error when I 
> run this same applet in Eclipse, either as an applet or as application 
> using Roedy Green's "Hybrid/switchhitter" technique.
> 
> This is the line that it doesn't like: 
> 
>        switch(FooConstants.DESIRED_FORMAT) {
> 
> The relevant line of FooConstants is: 
> 
>     public static final Formats DESIRED_FORMAT = Formats.PARAGRAPH_FORMAT;
> 
> And Format is defined as follows:
> 
> public enum Formats {
> 
>     /** Bulleted list. */ 
>     LIST_FORMAT, 
>     
>     /** Paragraph. */
>     PARAGRAPH_FORMAT
> }
> 
> 
> Can anyone tell me why I'm getting this error? Also, I'm curious to know 
> why this error doesn't occur when I run the applet in Eclipse.

As suggested here, you may have re-factored FooConstants or Formats 
since the last full build:

<https://groups.google.com/forum/#!msg/comp.lang.java.programmer/NrVbkOkDBsg/BtW0CQeuhDUJ>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#9314

FromNovice <novice@example..com>
Date2011-10-30 15:14 +0000
Message-ID<Xns9F8E726886779jpnasty@94.75.214.39>
In reply to#9313
"John B. Matthews" <nospam@nospam.invalid> wrote in
news:nospam-7ED1EB.10073030102011@news.aioe.org: 

> In article <Xns9F8E6573E3F9Fjpnasty@94.75.214.39>,
>  Novice <novice@example..com> wrote:
> 
>> I'm getting an unexpected runtime error when I execute my applet on a
>> webpage from a jar. I should note that I do NOT get this same error
>> when I run this same applet in Eclipse, either as an applet or as
>> application using Roedy Green's "Hybrid/switchhitter" technique.
>> 
>> This is the line that it doesn't like: 
>> 
>>        switch(FooConstants.DESIRED_FORMAT) {
>> 
>> The relevant line of FooConstants is: 
>> 
>>     public static final Formats DESIRED_FORMAT =
>>     Formats.PARAGRAPH_FORMAT; 
>> 
>> And Format is defined as follows:
>> 
>> public enum Formats {
>> 
>>     /** Bulleted list. */ 
>>     LIST_FORMAT, 
>>     
>>     /** Paragraph. */
>>     PARAGRAPH_FORMAT
>> }
>> 
>> 
>> Can anyone tell me why I'm getting this error? Also, I'm curious to
>> know why this error doesn't occur when I run the applet in Eclipse.
> 
> As suggested here, you may have re-factored FooConstants or Formats 
> since the last full build:
> 
> <https://groups.google.com/forum/#!msg/comp.lang.java.programmer/NrVbkO
> kDBsg/BtW0CQeuhDUJ> 
> 

Thanks for the suggestion, John, but it didn't work. I did a clean and 
rebuild of the project, then ran my Ant script to compile the code, jar 
it, and send the jar to the server but I'm still getting the same error 
in the same place when I execute the applet on a web page. The applet 
continues to run just fine in Eclipse, both as an applet and an 
application.

I did some googling looking for other reports of this error and found a 
suggestion to put a try/catch around the problem code so I did that:

        try {
        switch(FooConstants.DESIRED_FORMAT) {
        case PARAGRAPH_FORMAT:
            dataPanel.add(createScrollableBorderedTextAreaForParagraph
(this.doc.getDescriptionParagraph(entryNumber), 
this.doc.getDescriptionText()));
            break;
        case LIST_FORMAT:
            dataPanel.add(createScrollableBorderedTextAreaForList
(this.doc.getDescriptionSentences(entryNumber), 
this.doc.getDescriptionText(), LIST_BULLET_CENTER_DOT));
            break;
        }
        }
        catch (Throwable t) {
        	t.printStackTrace();
        }

Then I ran the Ant script again. The behaviour changed fairly 
dramatically after this change. When I try to run the applet in Firefox 
7, I get:

 java.lang.NoClassDefFoundError: Could not initialize class 
com.foo.FooConstants
 
The applet will not display. However, when I do the same thing in Opera 
11.52, the applet DOES display, although the console shows the same 
error. Ditto for Google Chrome: the applet displays but I get the error 
in the console. 

FooConstants is definitely in the jar - I have a little jarViewer class 
that I use to list the contents - so I'm not sure whether Java just isn't 
seeing it or is having some kind of problem initializing it.

I'm not sure what to try next because I don't really understand the 
underlying error.


-- 
Novice

[toc] | [prev] | [next] | [standalone]


#9315

FromStanimir Stamenkov <s7an10@netscape.net>
Date2011-10-30 17:52 +0200
Message-ID<j8jrrj$bpa$1@dont-email.me>
In reply to#9314
Sun, 30 Oct 2011 15:14:11 +0000 (UTC), /Novice/:

> I'm not sure what to try next because I don't really understand the
> underlying error.

Whenever you change something on the server, clean your browser 
cache first - you could be getting an old version of a class which 
linkage dependencies could not be satisfied with the newer versions 
of other classes the browser may get.

It would have helped if you have provided a full stack trace of the 
exception/error you're getting.

-- 
Stanimir

[toc] | [prev] | [next] | [standalone]


#9316

FromLew <lewbloch@gmail.com>
Date2011-10-30 08:45 -0700
Message-ID<21727861.871.1319989538099.JavaMail.geo-discussion-forums@prgt10>
In reply to#9314
Novice wrote:
> John B. Matthews wrote: 
> > Novice wrote:
> > 
> >> I'm getting an unexpected runtime error when I execute my applet on a
> >> webpage from a jar. I should note that I do NOT get this same error
> >> when I run this same applet in Eclipse, either as an applet or as
> >> application using Roedy Green's "Hybrid/switchhitter" technique.
> >> 
> >> This is the line that it doesn't like: 
> >> 
> >>        switch(FooConstants.DESIRED_FORMAT) {
> >> 
> >> The relevant line of FooConstants is: 
> >> 
> >>     public static final Formats DESIRED_FORMAT =
> >>     Formats.PARAGRAPH_FORMAT; 
> >> 
> >> And Format is defined as follows:
> >> 
> >> public enum Formats {
> >> 
> >>     /** Bulleted list. */ 
> >>     LIST_FORMAT, 
> >>     
> >>     /** Paragraph. */
> >>     PARAGRAPH_FORMAT
> >> }
> >> 
> >> 
> >> Can anyone tell me why I'm getting this error? Also, I'm curious to
> >> know why this error doesn't occur when I run the applet in Eclipse.
> > 
> > As suggested here, you may have re-factored FooConstants or Formats 
> > since the last full build:
> > 
> > <https://groups.google.com/forum/#!msg/comp.lang.java.programmer/NrVbkO
> > kDBsg/BtW0CQeuhDUJ> 
> > 
> 
> Thanks for the suggestion, John, but it didn't work. I did a clean and 
> rebuild of the project, then ran my Ant script to compile the code, jar 
> it, and send the jar to the server but I'm still getting the same error 
> in the same place when I execute the applet on a web page. The applet 
> continues to run just fine in Eclipse, both as an applet and an 
> application.
> 
> I did some googling looking for other reports of this error and found a 
> suggestion to put a try/catch around the problem code so I did that:
> 
>         try {
>         switch(FooConstants.DESIRED_FORMAT) {
>         case PARAGRAPH_FORMAT:
>             dataPanel.add(createScrollableBorderedTextAreaForParagraph
> (this.doc.getDescriptionParagraph(entryNumber), 
> this.doc.getDescriptionText()));
>             break;
>         case LIST_FORMAT:
>             dataPanel.add(createScrollableBorderedTextAreaForList
> (this.doc.getDescriptionSentences(entryNumber), 
> this.doc.getDescriptionText(), LIST_BULLET_CENTER_DOT));
>             break;
>         }
>         }
>         catch (Throwable t) {
>         	t.printStackTrace();
>         }
> 
> Then I ran the Ant script again. The behaviour changed fairly 
> dramatically after this change. When I try to run the applet in Firefox 
> 7, I get:
> 
>  java.lang.NoClassDefFoundError: Could not initialize class 
> com.foo.FooConstants
>  
> The applet will not display. However, when I do the same thing in Opera 
> 11.52, the applet DOES display, although the console shows the same 
> error. Ditto for Google Chrome: the applet displays but I get the error 
> in the console. 
> 
> FooConstants is definitely in the jar - I have a little jarViewer class 
> that I use to list the contents - so I'm not sure whether Java just isn't 
> seeing it or is having some kind of problem initializing it.

Java just isn't seeing it.  You have the ".class" file in the wrong subdirectory.

> I'm not sure what to try next because I don't really understand the 
> underlying error.

The underlying error is that 'FooConstants' is not in the correct place in the classpath.  It is not Java's fault.

Instead of providing us with a partial clue (that never contains the whole answer and sometimes contains none of it), put together a Simple, Self-Contained Compilable Example (SSCCE):

http://sscce.org/

What you will find is that the class 'FooConstants' is not in the directory location in the classpath that corresponds to its package.

Show us the source for 'FooConstants', please (no more snippets!) and in what directory it resides within the JAR ("jar tf jarfile | grep FooConstants" being a convenient way to figure that out).

http://sscce.org/

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#9319

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-30 23:57 -0700
Message-ID<gghsa7t55leng0q1s8vpokff46g43b3gu9@4ax.com>
In reply to#9314
On Sun, 30 Oct 2011 15:14:11 +0000 (UTC), Novice <novice@example..com>
wrote, quoted or indirectly quoted someone who said :

> java.lang.NoClassDefFoundError: Could not initialize class 
>com.foo.FooConstants

My guess is FooConstants is missing from the jar or is out of date.
Look at the jar with Winzip to look at the sizes and dates to see if
it what you expect.

NoClassDefFoundError has more causes than you can shake a stick at.
See
http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR

Make sure you delete all the *.class and *.jar files before you build
to ensure any static finals get propagated.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things. 
We understand human mental processes only slightly better than
a fish understands swimming. 
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence), 
the short-circuit OR operator (|| in Java), 
and LISP (LIst Processing Language) that makes EMACS 
(Extensible MACro System) so addictive.

[toc] | [prev] | [next] | [standalone]


#9320

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-31 01:28 -0700
Message-ID<sshsa7hn6806727ctr3b38ss63ioeap3i1@4ax.com>
In reply to#9314
On Sun, 30 Oct 2011 15:14:11 +0000 (UTC), Novice <novice@example..com>
wrote, quoted or indirectly quoted someone who said :

> java.lang.NoClassDefFoundError: Could not initialize class 
>com.foo.FooConstants

for future reference see
http://mindprod.com/jgloss/runerrormessages.html#EXCEPTIONINITALIZERERROR
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things. 
We understand human mental processes only slightly better than
a fish understands swimming. 
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence), 
the short-circuit OR operator (|| in Java), 
and LISP (LIst Processing Language) that makes EMACS 
(Extensible MACro System) so addictive.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web