• Advertisement

Archived

This topic is now archived and is closed to further replies.

Help with java installation

This topic is 5027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just began learning java and I recently installed their SDK, but when I trie to run the class files I get after compiling I get the following error "Exeption in thread "main" java.lang.NoClassDefFoundError" why? I tried searching for it with google but came up with no real answere.

Share this post


Link to post
Share on other sites
Advertisement
I'm guessing that at the command line you typed something like: java myclass.class Instead try typing java myclass (leave off the .class extension).

edit: also, you might try adding . to the class path.

[edited by - SiCrane on April 13, 2004 2:12:47 PM]

Share this post


Link to post
Share on other sites
Let''s pretend you have a simple java prog called HelloWorld.java. You can compile it with,

javac HelloWorld.java

You should then get a class called HelloWorld.class. To run this class you can do the following,

java -classpath . HelloWorld

The reason for the -classpath . (notice the dot, that''s important) is because by default Java does not include the current working directory (I believe it''s a security measure, you''ll notice the same thing in a Unix environment). The dot represent the current working directory.

That should run. However, if you when you wrote your java prog you told it to be part of a package, and again, as an example, you told the prog it was part of the package com.company.hello then you would need to do,

java -classpath . com.company.hello.HelloWorld

Okay... if you''re reading that last bit and it''s confusing, don''t worry... Try running it as described in the first two bits. You''ll get the hang of it

Share this post


Link to post
Share on other sites
nope get the same error, (this must be the hardest language ever , can''t even get by the compiler (the borland one that I found was no better))

Share this post


Link to post
Share on other sites
please post the following:

1) the source of your program (proabably not the problem but it never hurts)

2) the exact text of how you are compiling the program and any messages you get in response

3) the exact text of how you are running the program and any messages that you get in response

and maybe the directory listing of the folder in which your code sits. post the code in [*source][/source] tags (without the asterix)

-me

[edited by - Palidine on April 14, 2004 12:55:12 PM]

Share this post


Link to post
Share on other sites
I made some changes to the system, so that i can run class files by double clicking on them, and compile java files with an option in the context menu.

You can try to compile and run your files by putting them in the same directory as the "java" and "javac" program, and than use the command prompt.

Share this post


Link to post
Share on other sites
quote:
Original post by kappa
I tried searching for it with google but came up with no real answer.
Unless you provide information when asking a question, you''ll get no real answers. (Well, you might get lucky and someone might stumble across your solution.)

A good question describes the situation adequately (most people can not describe code situations without posting the actual code), explains what has been tried (if running command-line tools, give the exact invocation string, PATH and other such environment data) and the exact results (copy and paste the error message) as well as the desired results/objective.

Share this post


Link to post
Share on other sites

1.
class helloDan
{
public static void main()
{
System.out.println("HelloWorld");
}
}

(in \j2sdk1.4.2_04\bin)
2.
"javac freq.java" to compile(to helloDan), no errors

3.
"java -classpath . helloDan" get error
"Exeption in thread "main" java.lang.NoClassDefFoundError"

same with

java helloDan
java -classpath [path] helloDan







[edited by - kappa on April 14, 2004 1:13:19 PM]

Share this post


Link to post
Share on other sites
I suppose it might not help (since you have probably already tried that ), but just in case :
- use the proper -classpath option (as explained earlier), or declare your CLASSPATH environment variable as something that contains either "." (the current directory) or the path to the directory that contains your classes. That will be much cleaner than putting everything in the java/bin directory
- check that you are lauching the class file with
java NameOfTheClass  
, with no .class, no .java, no .net, no .com nor anything that starts with a dot. Dots are evil outside of a java code. In a java code, dots are the god-given tokens that helps you make your code as obfuscated as an old-school C code, and slower than a burgundish snail, by calling
  thing.please().do().something().that().i().really(need).now;  

- check that your main methods is called like this :
 public static void main(String[] argv){ //blabla }  
in a class file that contains a class with the same name (case sensitively) as the file''s one. I know it''s stupid, but that can happen to every one.
- remember to stay Zen and believe that Jesus is yo... what ? No proselytism on this forum ? sh***e.

And **No**, Java is not the hardest language in the world. If you doubt it, try Fortran ().

Hope that could help.
pH

Share this post


Link to post
Share on other sites
Okay, I saw your code, it is definitely the (String[] argv) part that is wrong.
You need to declare the main methods with an array of strings as a parameter, so that the VM knows it is the entry point. But as you may want to call a method main, the compiler doesn't complain.

PS : ususally, the convention is to give classes a name that starts with an Upercase letter. You should have called your file (and, therfore, your class) HelloDan.java (and your class HelloDan).

What you want is :

class HelloDan {
public static void main(String[] argv){
System.out.println("Hello Dan, it's pH !!");
}
}



Good luck.
pH
[edited by - trivierph on April 14, 2004 1:18:20 PM]

[edited by - trivierph on April 14, 2004 1:21:09 PM]

[edited by - trivierph on April 14, 2004 1:21:33 PM]

Share this post


Link to post
Share on other sites
gah, and I thougth that it was a compiler error, thanx all.

and befunge is deffinitly the hardest language

Share this post


Link to post
Share on other sites
quote:

and befunge is deffinitly the hardest language


Can I had that gaelic and french are perhaps harder thatn any programming langage
Except of course Fortran.

Okay, let''s stop now, go write some classes, man !

Share this post


Link to post
Share on other sites
Your class also needs to be public, and be in a file named after the class (i.e. "helloDan.java"). You can put other classes in a java file but they won''t be accessible from the outside. The general rule is that Foo.java contains

- public class Foo
- optionally, non-public classes which Foo needs for "support".

BTW, it''s conventional in Java, like in most C++ communities (except the hardcore Hungarian-notation-using ones) to begin class names with a capital letter.

Share this post


Link to post
Share on other sites

  • Advertisement