Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2008, 08:17 AM
Member
 
Join Date: Mar 2008
Posts: 43
Rep Power: 0
fogus is on a distinguished road
Default Help with "hello world"
After 3 hours I have decided to turn this over to the experts.

The helloworld.java program is:

Code:
public class helloworld
{
   public static void main(String args[])
   {
      System.out.println("hello world");
   }
}
The result is:
Code:
>java helloworld
java.lang.NoClassDefFoundError: helloworld
Caused by: java.lang.ClassNotFoundException: helloworld
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" >Exit code: 1
I am using SciTE as an editor, but I get the same result in the command prompt, when I use:
Code:
command.compile.*.java=javac $(FileNameExt)
command.build.*.java=javac *.java
command.go.*.java=java $(FileName)
I think this has something to do with my "environment variables"; JCreator can run this program just fine.

Here are the relavent environment variables:
System Variables\CLASSPATH:
C:\Program Files\Java\jdk1.6.0_04\src.jar;
C:\Program Files\Java\jdk1.6.0_04\lib\dt.jar;
C:\Program Files\Java\jdk1.6.0_04\lib\tools.jar;
C:\Program Files\Java\jdk1.6.0_04\jre\lib\il8n.jar;
C:\Program Files\Java\jdk1.6.0_04\jre\lib\jaws.jar;
C:\Program Files\Java\jdk1.6.0_04\jre\lib\rt.jar;
C:\Program Files\Java\jdk1.6.0_04\jre\demo\sound\JavaSound.ja r;
C:\Program Files\Java\jdk1.6.0_04\demo\jfc\SwingSet2\SwingSet 2.jar;
C:\Program Files\Java\jdk1.6.0_04\demo\jfc\SwingApplet\SwingA pplet.jar;
C:\Program Files\Java\jdk1.6.0_04\;
C:\Program Files\Java\jdk1.6.0_04\Bin;
C:\Program Files\Java\jdk1.6.0_04\Lib;
(all on one line, of course)

User Variables\PATH:
C:\Program Files\Java\jdk1.6.0_04\bin

However, when I run SciTE pointed at:

Code:
command.compile.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\javac $(FileNameExt)
command.build.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\javac *.java
command.go.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\java $(FileName)
I get a slightly different message:


Code:
java.lang.NoClassDefFoundError: helloworld
Caused by: java.lang.ClassNotFoundException: helloworld
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main" >Exit code: 1
1. Anyone care to clue me in on why the default installation of JDK does not work with the command prompt?
2. What should my environment variables be?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-11-2008, 01:42 PM
Member
 
Join Date: Feb 2008
Posts: 74
Rep Power: 0
Menre is on a distinguished road
Default
Hi,

I have noticed something wrong in your coding. In your programme you wrote the line below

public static void main(String args[])

It should be written the way below

public static void main(String[] args )

I hope this solves your problem.

Regards,
Menre
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-11-2008, 02:17 PM
Member
 
Join Date: Mar 2008
Posts: 1
Rep Power: 0
neethur is on a distinguished road
Default
I have lost my httpservlet.jar file from my system, can anyone help me by sending one to my id "neethmohan@yahoo.com"
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-11-2008, 09:34 PM
Member
 
Join Date: Dec 2007
Posts: 17
Rep Power: 0
Jman is on a distinguished road
Default
Hi Fogus

I think your problem is that you have not yet compiled your code. I say think because you just mention running java helloworld. If I am wrong please forgive me. But here goes anyway. Try the following
1. save the code as helloworld.java
2. cd to the directory you stored the helloworld.java file
3. run javac helloworld.java
4. then run java helloworld
this should work.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-12-2008, 02:03 AM
Member
 
Join Date: Mar 2008
Posts: 43
Rep Power: 0
fogus is on a distinguished road
Default
You know, Jman, I had tried those steps before, but for some reason things just started to work all of a sudden. Perhaps my environment variables just didn't kick in for a while.

Thanks everyone; the issue has been solved.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-26-2008, 08:24 PM
Member
 
Join Date: Dec 2008
Location: US
Posts: 2
Rep Power: 0
Codapalpjonna is on a distinguished road
Send a message via ICQ to Codapalpjonna
Default iixkhocxzuqkwdcdhzrofufvelcptbanmowhello guys need advice
qxfskkdzgpgyaujawell, hi admin adn people nice forum indeed. how's life? hope it's introduce branch
__________________
always online
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-29-2008, 08:24 PM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
anandmohans is on a distinguished road
Default
To execute any class, the CLASSPATH variable must point to the location where .class file is located. Typically, when you compile & execute your code using some IDE, the class is made available to JVM by the IDE. In other cases you will have to ensure that class file is present at the location specified by CLASSPATH.
For more details, you can refer to following link:
j2eeconcepts.com/j2eeconcepts/pages/java/general/classpath.htm
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 12-29-2008, 08:47 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
sorry to disappoint you anandmohans, but the ones who matter, in particular fogus, are no longer reading this thread as it is a zombie thread that has been resurrected for unknown reasons by Codapalpjonna, who I suspect is a troll.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 12-29-2008, 11:04 PM
Member
 
Join Date: Mar 2008
Posts: 43
Rep Power: 0
fogus is on a distinguished road
Default
The funny thing is that I am having this problem again right now.

I have tried all the usual things and I set my CLASSPATH to:

C:\Program Files\Java\jdk1.6.0_10\src.jar;C:\Program Files\Java\jdk1.6.0_10\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\il8n.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\jaws.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_10\jre\demo\sound\JavaSound.ja r;C:\Program Files\Java\jdk1.6.0_10\demo\jfc\SwingSet2\SwingSet 2.jar;C:\Program Files\Java\jdk1.6.0_10\demo\jfc\SwingApplet\SwingA pplet.jar;C:\Program Files\Java\jdk1.6.0_10\;C:\Program Files\Java\jdk1.6.0_04\Bin;C:\Program Files\Java\jdk1.6.0_10\Lib;

1. Any ideas?
2. Why doesn't python have this problem?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 12-29-2008, 11:18 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
this is just too weird!

anyway, are you talking about your OS environment's classpath, if so, don't mess with it. Instead compile with the -cp switch. I usually use -cp . or something similar.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
failure at Class.forName("oracle.jdbc.driver.OracleDriver"); RonNYC Eclipse 1 03-14-2008 03:51 PM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 08:53 AM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-27-2007 11:59 PM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-25-2007 11:55 PM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 07:32 AM


All times are GMT +2. The time now is 07:04 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org