Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 10-10-2005, 04:57 AM   #1 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
Running a java program

I have managed to succesfully compile the following java program and it has created the class file correctly.

However when I try to run the program DOS comes up with this error.

Exception in thread "main" java.lang.NoClassDefFoundError: then the file name

this is the code of the main file
Code:
public class Hello { public static void main (String[] args) { System.out.println("Hello World"); } }
__________________

Last edited by redhead : 10-10-2005 at 06:57 AM. Reason: Use of [code] tags added
Java2 is offline   Reply With Quote
Old 10-10-2005, 07:00 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
Have you checked the documentation, specificaly the part about case sensitivity
Quote:
Be Careful When You Type

Type all code, commands, and file names exactly as shown. The Java compiler and interpreter are case-sensitive, so you must capitalize consistently.

Hello not equal hello
Suns forum reveals there might be an error in your $CLASSPATH setting, since some have had the exact same probelm.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-10-2005, 07:28 AM   #3 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
sorry being new to all this, could u explain how i can change the classpath name
__________________
Java2 is offline   Reply With Quote
Old 10-10-2005, 09:53 AM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
If you're using Windows, it depends on the version of Windows you're using. In XP, you can right-click on My Computer and select Properties. Click on the Advanced tab and at the bottom hit the button labeled "Environmental Variables". "CLASSPATH" should be listed under "System variables". Be sure to include "." in your classpath, as that can often be the source of "NoClassDefFound" errors.

In Windows, the CLASSPATH is broken up with semi-colons for each directory you wish to include.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-10-2005, 10:18 AM   #5 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
A few path names was thrown around in that forum. so wot do i need to put in it and where will i need to save my java files.
__________________
Java2 is offline   Reply With Quote
Old 10-10-2005, 02:58 PM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Maybe Malcolm's link about setting up his cutter code editor could give you some pointers. http://fundza.com/cutter/installation/installation.html
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 10-10-2005, 03:20 PM   #7 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
Quote:
Originally Posted by Java2
A few path names was thrown around in that forum. so wot do i need to put in it and where will i need to save my java files.
You need "." so as to be able to run it from *anywhere*.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-11-2005, 12:39 AM   #8 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
Ok, i have added a "." into the class path (i think anyway, unless i have got this entirely wrong) there is a link to my below. any mistakes please point it out.

http://i14.photobucket.com/albums/a3...7/untitled.jpg

then just copy the image and paste it into a new application, it should appear more clear.
__________________
Java2 is offline   Reply With Quote
Old 10-11-2005, 12:51 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
Thats the $TEMP variable you're editing there.. It has nothing todo with $CLASSPATH.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-11-2005, 12:52 AM   #10 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
ok, so how do i chage the classpath to "."
__________________
Java2 is offline   Reply With Quote
Old 10-11-2005, 02:39 AM   #11 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
Follow the directions given by Belisarius, if theres no system variable named CLASSPATH, then create a new one and fill in the "." aswell as your location of your java installation ie: c:\program files\java\jdk1.5.0\bin\;.;%CLASSPATH%;
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-11-2005, 03:28 AM   #12 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
Ok its been created still hasn't work.

as before here is a link to the screenshot

http://i14.photobucket.com/albums/a3...2ndattempt.jpg
__________________
Java2 is offline   Reply With Quote
Old 10-11-2005, 01:59 PM   #13 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
For the record, "c:\program files\java\jdk1.5.0\bin\" isn't useful in the CLASSPATH - it doesn't contain any Java classes.

Here's what I need to help you - I need screenshots of the following:

- Your source code (I want an actual screen shot, not a cut and paste).
- A directory listing of the code you're trying to run. (Type 'dir' in the cmd window. If the listing is too long for the window, create a new directory and move your code there).
- A compile and an attempt to run the program. Include an 'echo %CLASSPATH%' as well.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-12-2005, 01:21 AM   #14 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
Ok this should be all you need

http://i14.photobucket.com/albums/a3...mandPrompt.jpg

http://i14.photobucket.com/albums/a3...SourceCode.jpg

thanks for your help
__________________
Java2 is offline   Reply With Quote
Old 10-12-2005, 01:45 AM   #15 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
Don't use the full path when running the Java program, just run "java Hello".
__________________
GitS
Belisarius is offline   Reply With Quote
Reply


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

vB 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
Java Resources Belisarius Java 0 03-28-2005 02:03 PM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Compiling Java program to a stand-alone application Punch-M6.net Java 4 07-27-2004 08:22 PM
Program Call to AS400 using JTOpen sde Java 0 05-12-2004 07:08 AM
What is OOP and Java? srt42 Java 0 04-07-2003 01:21 AM


All times are GMT -8. The time now is 12:35 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle