Results 1 to 17 of 17
- 03-14-2010, 09:28 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
my code compiling but not running
i am trying to run this simple code but this should be in package girish which is on desktop
i want this program to work but package girish should be on desktop
and error also is given below...
i pass input through command line parameters
ANY SUGGESTIONS
package girish;
class Greeter
{
String name;
Greeter(String n)
{
this.name=n;
}
public String sayHello()
{
String s="Hello";
String f=s+" "+this.name;
return f;
}
public static void main(String[] args)
{
Greeter g=new Greeter(args[0]);
System.out.println(g.sayHello());
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: Greeter
Caused by: java.lang.ClassNotFoundException: Greeter
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)
- 03-14-2010, 09:51 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,417
- Blog Entries
- 7
- Rep Power
- 17
The fully qualified name of your class is girish.Greeter and the class file should be stored in a directory "girish" somewhere. Also read about the classpath variable.
kind regards,
Jos
- 03-14-2010, 10:04 AM #3
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
What JosAH said, and also, you need to run "java girish/Greeter <args>" and not "java girish/Greeter.class <args>".
-Gary-
- 03-14-2010, 02:23 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
my classpath file is set and class files comes to directory girish itself...
but still not running
y should i give full path like "java girish/Greeter" name when everything is set
- 03-14-2010, 02:34 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,417
- Blog Entries
- 7
- Rep Power
- 17
Suppose your directory "girish" is a subdirectory of directrory "X", so your class file can be found in /X/girish/Greeting.class. Your classpath variable is supposed to contain "X" when you want to run your class girish.Greeting. e.g. the following command will do the job:
kind regards,Java Code:java -cp /X girish.Greeting
Jos
- 03-14-2010, 02:56 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
u mean to say when i run each class file i should give full path name like
"java -cp C:\Documents and Settings\giri\Desktop\girish\Greeter"
- 03-14-2010, 03:00 PM #7
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
if i remove my package statement it works but i want to create packages and want to specify in java files..
- 03-14-2010, 04:33 PM #8
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Read this:
Managing Source and Class Files (The Java™ Tutorials > Learning the Java Language > Packages)
And read the five pages leading up to that one too. Also, read again what JosAH said.
-Gary-
- 03-14-2010, 06:33 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,417
- Blog Entries
- 7
- Rep Power
- 17
- 03-15-2010, 09:32 AM #10
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
@JoSAH and @gcalvin
Thanku for ur support
finally i understood it...
thanku thanku thanku
- 03-15-2010, 09:35 AM #11
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
but i have to give java girish\Greeter to run ..
what if i have hierarchy of packages like X/Y/Z then i have to give "java X/Y/Z/*.class"
to run
is there any shortcut to run
- 03-15-2010, 09:58 AM #12
sure.
- you can build a jar file Using JAR Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files) so that you can start your java app with java -jar app.jar or
- you can create a shortcut from your os that executes "java X/Y/Z/app". put the shortcut on the desktop so you can start it with a doubleclick or in a directory in the systempath, so you can call your shortcut from everywhere. but remember: don't add the extension class to the classfile when you call java!
any other suggestions?Last edited by j2me64; 03-15-2010 at 10:06 AM.
- 03-15-2010, 10:07 AM #13
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
@j2me64
i just wanted to show i am running class file so i put class extension there
- 03-15-2010, 10:09 AM #14
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
You have two choices at this point: change directories up one level and try java test.PackTest, or add the top of your development class hierarchy to the CLASSPATH environmental variable. Then you will be able to use java test.PackTest from any directory, and Java will find the right .class file. For example, if you are working on your source code in a directory called C:\\myjava, then set your CLASSPATH to .;C:\\myjava;C:\\java\\classes
Can anyone explain whats the second part exactly means..
add the top of your development class hierarchy to the CLASSPATH environmental variable.
pls if u can explain with respect to my example..
my package is on desktop
- 03-15-2010, 10:27 AM #15
afaik: when you specify a subdirectory, you are NOT specifying the directories above it, so they will not be searched for classes. so if you want this, add the top of your directory to the CLASSPATH environmental variable or with -classpath <topofyourdirectory>. for detail, see my pm.Last edited by j2me64; 03-15-2010 at 10:37 AM.
- 03-15-2010, 05:31 PM #16
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
thanku j2me64 for pm
kind regards
GIRI
- 03-16-2010, 04:45 PM #17
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
JAVA ME - Problems compiling and running in Eclipse
By Nicsoft in forum EclipseReplies: 2Last Post: 03-20-2009, 10:58 AM -
Help me out in compiling the source code
By aks.nitw in forum Advanced JavaReplies: 3Last Post: 10-17-2008, 08:33 AM -
Trouble compiling code
By waelhelbawi in forum New To JavaReplies: 1Last Post: 05-12-2008, 04:25 AM -
Compiling and running code in runtime
By tim in forum New To JavaReplies: 4Last Post: 01-27-2008, 06:58 PM -
Importing / compiling and running with .jar package
By splinter64uk in forum New To JavaReplies: 1Last Post: 12-05-2007, 02:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks