Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Exception in thread "main" java.lang.NoClassDefFoundError: Just

Reply
Thread Tools

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

 
 
Nikhil
Guest
Posts: n/a
 
      04-03-2007
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

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      04-03-2007

"Nikhil" <> wrote in message
news: ups.com...
> 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


http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR

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


 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      04-04-2007
Oliver Wong wrote:
> "Nikhil" <> wrote in message
> news: ups.com...
>> 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

>
> http://mindprod.com/jgloss/runerrorm...SDEFFOUNDERROR
>
> 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.
>


Doesn't the class need to be public?

--
Lew
 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      04-04-2007
Nikhil wrote:
> 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


Try:

java -cp . Just

instead of:

java Just

Arne
 
Reply With Quote
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      04-04-2007
Lew wrote:
>> "Nikhil" <> wrote in message
>> news: ups.com...
>>> class Just
>>> {
>>> public static void main(String[] args)
>>> {
>>> System.out.println("Hello World!");
>>> }
>>> }


> 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
 
Reply With Quote
 
Jussi Piitulainen
Guest
Posts: n/a
 
      04-04-2007
Arne Vajhøj writes:
> Lew wrote:
>>> Nikhil wrote:
>>>
>>>> class Just
>>>> {
>>>> public static void main(String[] args)

....
>> 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.


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>
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      04-04-2007
Jussi Piitulainen wrote:

> 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


 
Reply With Quote
 
Jussi Piitulainen
Guest
Posts: n/a
 
      04-04-2007
Chris Uppal writes:
> Jussi Piitulainen wrote:
>
>> 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.


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.

>

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      04-05-2007
Jussi Piitulainen wrote:
> Arne Vajhøj writes:
>> Lew wrote:
>>>> Nikhil wrote:
>>>>
>>>>> class Just
>>>>> {
>>>>> public static void main(String[] args)

> ...
>>> 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.

>
> 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>


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

Arne
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      04-05-2007
Lew wrote:
>>> 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.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200704/1

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swingworker thread or just a plain thread? smily Software 0 07-08-2010 04:03 PM
Win a copy of the just::thread C++0x thread library Anthony Williams C++ 1 10-19-2009 08:43 PM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Terminating program run from thread (not just the thread) Jeffrey Barish Python 0 05-28-2004 02:02 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57