This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!

simon coldcat

Greenhorn
+ Follow
since Jul 22, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by simon coldcat

Hello All. I tried Jon's suggestion this morning and it worked! I am off and running with JAVA. I have written a couple of little programs, and they are working.

I want to thank you all for your help. All of the suggestions that you posted were necessary changes for me to get started. I don't think I would have figured out all three changes by myself!

Thank you, thank you, thank you!

Simon
14 years ago

Originally posted by Ernest Friedman-Hill:
The declaration of "main" has to be

public static void main(String[] argv) {
...

The only thing you can change on that line is the word "argv", which is an arbitrary variable name. You've left out the "public", the "static," and the "String[] argv", and so the launcher can't find the method it's looking for.



Hi Ernest. Thanks for your input. I made my code the following:

class MyFirstApp{

public static void main(String[] myarg){
System.out.print("Hello World");
}
}

Now I get the following from the Command Prompt:
--------------
C:\User\Java>java myfirstapp.class
Exception in thread "main" java.lang.NoClassDefFoundError: myfirstapp/class
------------------
C:\User\Java>java myfirstapp
Exception in thread "main" java.lang.NoClassDefFoundError: myfirstapp (wrong nam
e: MyFirstApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)

------------------
Any Ideas? Thanks, Simon
14 years ago

Originally posted by Marilyn de Queiroz:

Rather than "java MyFirstApp.class", you should type "java MyFirstApp"



Thanks for your reply Marilyn. I tried typing "java MyFirstApp", and I received the following error:

"Exception in thread "main" java.lang.NoSuchMethodError: main"
14 years ago
Help! I can compile my MyFirstApp.Java file, but I cannot run the MyFirstApp.Class File. I've tried several suggestions posted at various websites that say it is my CLASSPATH environment variable and suggest changes, but nothing works. Below I have included my code and the latest settings I am working with. I am running Windows XP, and I wonder if this is part of the problem?

I am so frustrated! I would greatly appreciate some help!
Thank you,
Simon

This is my file MyFirstApp.Java:
------------------------------------------------------------
class MyFirstApp{

void main(){
System.out.print("Hello World");
}
}
-------------------------------------------------------------
My PATH variable is the following: "C:\Program Files\Java\jdk1.5.0_04\bin"
My CLASSPATH variable is the following: "."
Please note that my PATH variable is a system variable, and I can query it through the Command Prompt. My CLASSPATH variable is User Variable. I can see it in the Control Panel->System->Advanced->Environment Variables...but when I query it through the Command Prompt I get an error.
-------------------------------------------------------------
When I type "javac MyFirstApp.java" at the command prompt, the file compiles fine and the MyFirstApp.class file is created (in the same directory)
-------------------------------------------------------------
When I type "java MyFirstApp.class" I get the following error:
"Exception in thread "main" java.lang.NoClassDefFoundError: myfirstapp/class"
--------------------------------------------------------------
When I type "java -version" I get the following:
"java version "1.5.0_04"
java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client UM (build 1.5.0_04-b05, mixed mode, sharing)"
-----------------------------------------------------------------
14 years ago