Skip to main content

NewBie Question

1 reply [Last post]
esadeghi
Offline
Joined: 2011-04-11
Points: 0

i write two java class :
MyFirst.Java
package ican;
public class MyFirst
{
public static void main(String[] args)
{
System.out.print("Ehsan");
}
}
and
HelloWorldApp.java
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
and compile them by :
javac -d javastudy d:\javastudy\MyFirst.java and javac HelloWorldApp.java
but when i want to run them following error raise :
D:\JavaStudy\ican>java ican.MyFirst
Exception in thread "main" java.lang.NoClassDefFoundError: ican/MyFirst
Caused by: java.lang.ClassNotFoundException: ican.MyFirst
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)
Could not find the main class: ican.MyFirst. Program will exit.
and
D:\JavaStudy>java HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
Caused by: java.lang.ClassNotFoundException: HelloWorldApp
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)
Could not find the main class: HelloWorldApp. Program will exit.
How can i fix it?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
slash13
Offline
Joined: 2011-06-04
Points: 0

Hey.
If you're using console, I suggest you to go to the folder where you have the .java files with cd command.
e. g. cd d:\javastudy
and then javac Filename.java
Also if you're starting in Java programming I might suggest you to use an IDE