Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 06:25 PM
Member
 
Join Date: Jul 2007
Posts: 4
bks504 is on a distinguished road
Problem while executing programs
while executing a java prog i am getting a Error.:
Exception in thread "main" java.lang.NoClassDefFoundError: first
Program: first.java
class first
{
public static void main(String args[])
{
System.out.println("Hello");
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 07:03 PM
Member
 
Join Date: Jul 2007
Posts: 41
paty is on a distinguished road
it could be:
* Name of the file class that must be executed does not have the same name that the principal class (that one that it contains the method main)

* One has written the extension class later of the name of the principal class on having tried to execute the program.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2007, 08:00 PM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
Hi,
Everyday somebody thread this same problem!! anyway the rootcasts may be
1.Filename & class name mismatch
2.Class Path problem
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-31-2007, 09:59 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
Everyday somebody thread this same problem!!
You are right, Swamipsn.

We can create a FAQ for these, put a sample question there and place references to similar threads.

Then when we see a similar thread we can give the FAQ url and question number. Then the user having same problem can follow the links to solve his problem. And if he can not solve he can continue asking..

What do you think?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-31-2007, 11:03 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
I like it very much. There does seem to be quite a bit of repetition in certain questions.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-01-2007, 11:40 AM
Member
 
Join Date: Jul 2007
Posts: 4
bks504 is on a distinguished road
the filename i typed is same
this is the way i executed
>javac first.java
this is compiling correctly but when i am executing
>java first
it is giving Exception
i even set the classpath in this manner
>set CLASSPATH=c:\java\jdk1.6.0\bin
but the same error i am getting please help me
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-01-2007, 11:40 AM
Member
 
Join Date: Jul 2007
Posts: 4
bks504 is on a distinguished road
the filename i typed is same
this is the way i executed
>javac first.java
this is compiling correctly but when i am executing
>java first
it is giving Exception
i even set the classpath in this manner
>set CLASSPATH=c:\java\jdk1.6.0\bin
but the same error i am getting please help me
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-01-2007, 12:23 PM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
Hi,
Check first.class file is crated or not? after the successful compilation .class
file must be there. Then check .class is presented in the same directory which
is you try to run via command prompt. Then check java.exe file is presented in c:\java\jdk1.6.0\bin or not..? if it presented try to open it if its corrupted you cant open it.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-01-2007, 03:43 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
It is the class path. From the directory where first.class is, run this
>java -cp . first

The "-cp ." tells it to look in the current directory for class files.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 08-02-2007, 10:27 AM
Member
 
Join Date: Jul 2007
Posts: 4
bks504 is on a distinguished road
the solution of >java -cp . filename is giving correct results , where as when i am not typing the -cp i am getting the Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: filename
why it is happening like this , can any one give me the correct solution what should i do.Help me folks.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 08-02-2007, 03:32 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
Think of it this way, PATH tells windows where to find executable files when one is typed on the command line. CLASSPATH does the same thing but for Java so it can find class files to run. There are two ways to set the CLASSPATH: 1. set the environment variable CLASSPATH and the second is to use the -cp option when running java. With that said if the CLASSPATH=c:\java;c:\myclasses, java will only look in those two locations for class files. OK that is not entirely true it will also look in JAVA_HOME/lib/ext but that is besides the point. Now with the above set say you are trying to run a program in c:\code\myproject and you have a class Test.class in that directory. Java will not find the Test class because it is looking at the CLASSPATH only. The current directory is not implied. If you want Java to find your class you must tell it where to look. The "-cp ." says, "Hey look in the current directory too". Some like to put the "." at the end of the CLASSPATH env variable like so "c:\java;c:\myclasses;."

The best solution is to have a build script that sets the CLASSPATH explicitly for your project as you compile and run it.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
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
I need a simple programs mikau New To Java 2 02-11-2008 05:37 AM
Problem with executing mcal New To Java 2 02-09-2008 03:51 PM
Execute small java programs through Internet.........is thst possible?? atanu.dey New To Java 1 01-05-2008 09:48 PM
Problem with executing .jar files hiranya NetBeans 2 10-02-2007 09:24 PM
Executing a jar file peiceonly New To Java 2 04-06-2007 04:32 PM


All times are GMT +3. The time now is 09:47 PM.


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