Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Exception in thread "main" java.lang.NoClassDefFoundError: Just

Thread view: 
Nikhil - 03 Apr 2007 18:14 GMT
class Just
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }
}

Even this simple piece of code is not executing on my machine.
It compiles and at runtime it throw the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Just

please please please help me....
Thanks
Oliver Wong - 03 Apr 2007 18:41 GMT
> class Just
> {
[quoted text clipped - 8 lines]
>
> Exception in thread "main" java.lang.NoClassDefFoundError: Just

http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR

   If this doesn't fix it, you need to provide more info: What you typed
at the command prompt, what your classpath environment variable is set to,
what your directory structure is like, what directory you were in when you
typed in the command, etc.

   - Oliver
Lew - 04 Apr 2007 01:03 GMT
>> class Just
>> {
[quoted text clipped - 15 lines]
> what your directory structure is like, what directory you were in when you
> typed in the command, etc.

Doesn't the class need to be public?

Signature

Lew

Arne Vajhøj - 04 Apr 2007 01:55 GMT
>>> class Just
>>> {
[quoted text clipped - 3 lines]
>>> }
>>> }

> Doesn't the class need to be public?

It should according to JLS.

But java does not check.

There are several bug reports on that.

Arne
Jussi Piitulainen - 04 Apr 2007 10:17 GMT
>>>> class Just
>>>> {
>>>> public static void main(String[] args)
...
>> Doesn't the class need to be public?
>
[quoted text clipped - 3 lines]
>
> There are several bug reports on that.

Where does JLS say the class should be public? I failed to find it in
the index and in the following page that explains how a program is
executed. In none of the example programs on that page is the main
class public: they are all just "class Test".

<http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44444>
Chris Uppal - 04 Apr 2007 11:12 GMT
> Where does JLS say the class should be public? I failed to find it in
> the index and in the following page that explains how a program is
> executed.

I don't remember ever seeing any suggestion that the class has to be public
either.  Section 12.1.4 of the JLS states what that the main(String[]) method
must be public, static, and void,  but makes no mention of conditions that the
class itself must meet.

In any case, it's far from clear that that section is intended to be
normative -- it is embedded in a whole sequence of text which is clearly
descriptive rather than normative (and which explicitly references the JVM
spec, describing itself as "an overview").   In my opinion, whether or not it
is /intended/ to be normative, it damn-well /shouldn't/ be normative as
written; because if it was it would be requiring a behaviour that no complete
Java implementation has ever exhibited, nor ever will.  The public static void
main(String[]) thing is just how one way of launching Java programs works -- it
is incidental to that specific program, and other programs can and do work in
different ways.  That has been true ever since JDK 1.0.2, and probably before.

FWIW, the code for the java.exe launcher is simple, and it would be trivial to
add a check that the entry-point class is public (and perhaps that it's a
top-level class too).  Similar trivial code already exists only a few lines
away to ensure that main() is public.  So, if this is a bug, there hardly seems
to be a plausible reason for it to have remained unfixed for so long.

   -- chris
Jussi Piitulainen - 04 Apr 2007 12:53 GMT
>> Where does JLS say the class should be public? I failed to find it
>> in the index and in the following page that explains how a program
[quoted text clipped - 4 lines]
> main(String[]) method must be public, static, and void, but makes no
> mention of conditions that the class itself must meet.

Yes, it's quite explicit about _main_ being _public static void_, and
seems, to me, quiet about the class (other than actually using the now
allegedly forbidden form as example code).

As of now, I suspect the allegation upthread was mistaken.
Arne Vajhøj - 05 Apr 2007 01:26 GMT
>>>>> class Just
>>>>> {
[quoted text clipped - 13 lines]
>
> <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44444>

I just checked. You are rigth. I must have messed up class and method.

Arne
Jussi Piitulainen - 05 Apr 2007 12:00 GMT
>>>>>> class Just
>>>>>> {
>>>>>> public static void main(String[] args)
>> ...
>>>> Doesn't the class need to be public?
>>> It should according to JLS.
...
>> Where does JLS say the class should be public? I failed to find it in
>> the index and in the following page that explains how a program is
...
> I just checked. You are rigth. I must have messed up class and
> method.

Thanks.
Andrew Thompson - 05 Apr 2007 05:27 GMT
>>> class Just
>>> {
..
>Doesn't the class need to be public?

I watched the discussion about public (or not) classes
and the JLS with interest.  AFAIU, normal classes with
main() do not need to be public, OTOH *Applet* classes
must be public..

<sscce>
class DefaultAccessApplet extends
 java.applet.Applet {

 public void init() {
   add( new
     java.awt.Label("Default Access") );
 }
}
</sscce>

[console]
load: DefaultAccessApplet.class is not public or has no public constructor.
java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access
a
member of class DefaultAccessApplet with modifiers ""
[/console]

I could not say whether that was according to the JLS,
or simply an 'implementation detail' but it explains why
a lot of people are used to seeing 'main()' classes as
needing to be public, as so many (far too many) simple
code examples are written as Applets.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Oliver Wong - 05 Apr 2007 15:24 GMT
>>>> class Just
>>>> {
[quoted text clipped - 5 lines]
> main() do not need to be public, OTOH *Applet* classes
> must be public..

[snip code demonstrating this fact]

> I could not say whether that was according to the JLS,
> or simply an 'implementation detail' but it explains why
> a lot of people are used to seeing 'main()' classes as
> needing to be public, as so many (far too many) simple
> code examples are written as Applets.

   When I first learned Java, it was mainly through desktop applications
(and of those, mainly console based ones), as opposed to applets. I too
assumed that not only did the main method had to be public, but it's
containing class had to be so as well. I suspect it may be because the
(oversimplified) explanation I had internalized at the time was that main
had to be "public" so that java could "see" the method in order to invoke
it. If that were the case, it'd only make sense that java had to be able
to "see" the class as well.

   - Oliver
Arne Vajhøj - 04 Apr 2007 01:49 GMT
> class Just
> {
[quoted text clipped - 8 lines]
>
> Exception in thread "main" java.lang.NoClassDefFoundError: Just

Try:

  java -cp . Just

instead of:

  java Just

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.