Results 1 to 11 of 11
Thread: Problem while executing programs
- 07-31-2007, 04:25 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 4
- Rep Power
- 0
- 07-31-2007, 05:03 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
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.
- 07-31-2007, 06:00 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
Hi,
Everyday somebody thread this same problem!! anyway the rootcasts may be
1.Filename & class name mismatch
2.Class Path problem
- 07-31-2007, 07:59 PM #4levent Guest
You are right, Swamipsn.Everyday somebody thread this same problem!!
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?
- 07-31-2007, 09:03 PM #5
Senior Member
- Join Date
- Jul 2007
- Posts
- 135
- Rep Power
- 0
I like it very much. There does seem to be quite a bit of repetition in certain questions.
- 08-01-2007, 09:40 AM #6
Member
- Join Date
- Jul 2007
- Posts
- 4
- Rep Power
- 0
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
- 08-01-2007, 09:40 AM #7
Member
- Join Date
- Jul 2007
- Posts
- 4
- Rep Power
- 0
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
- 08-01-2007, 10:23 AM #8
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
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.
- 08-01-2007, 01:43 PM #9
Senior Member
- Join Date
- Jul 2007
- Posts
- 135
- Rep Power
- 0
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.
- 08-02-2007, 08:27 AM #10
Member
- Join Date
- Jul 2007
- Posts
- 4
- Rep Power
- 0
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.
- 08-02-2007, 01:32 PM #11
Senior Member
- Join Date
- Jul 2007
- Posts
- 135
- Rep Power
- 0
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.
Similar Threads
-
I need a simple programs
By mikau in forum New To JavaReplies: 2Last Post: 02-11-2008, 03:37 AM -
Problem with executing
By mcal in forum New To JavaReplies: 2Last Post: 02-09-2008, 01:51 PM -
Execute small java programs through Internet.........is thst possible??
By atanu.dey in forum New To JavaReplies: 1Last Post: 01-05-2008, 07:48 PM -
Problem with executing .jar files
By hiranya in forum NetBeansReplies: 2Last Post: 10-02-2007, 07:24 PM -
Executing a jar file
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2007, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks