Unable to Compile Application
I'm new to these forums so I just say hi before I make my post. :(hi):
I have just installed Java and Notepad++ and here is my application and program codes respectively:
Code:
public class MyApplication {
public static void main(String[] args) {
MyFirstProgram p = new MyFirstProgram();
p.start();
}
}
and
Code:
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
These two files are saved in "C:\MyFirstProgram". First I tried to compile and run the program using command prompt. The program comiled but the application did not:
Code:
C:\MyFirstProgram>javac MyFirstProgram.java
C:\MyFirstProgram>javac MyApplication.java
MyApplication.java:6: error: cannot find symbo
p.start();
^
symbol: method start()
location: variable p of type MyFirstProgram
1 error
I got my codes straight from my textbook so I don't understand what's wrong here. I thought maybe the CLASSPATH is incorrect, so I tried the following which also didn't work:
Code:
C:\MyFirstProgram>javac -cp . MyFirstProgram.java
C:\MyFirstProgram>javac -cp . MyApplication.java
MyApplication.java:6: error: cannot find symbol
p.start();
^
symbol: method start()
location: variable p of type MyFirstProgram
1 error
So I left command prompt and tried to compile and run the program using Notepad++ but I got the following error:
Code:
NPP_EXEC: "Java - Run"
CD: C:\MyFirstProgram
Current directory: C:\MyFirstProgram
java MyApplication
Process started >>>
java.lang.NoClassDefFoundError: MyApplication
Caused by: java.lang.ClassNotFoundException: MyApplication
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: MyApplication. Program will exit.
Exception in thread "main" <<< Process finished.
================ READY ================
So, what's causing this problem? Any help and guidance is greatly appreciated.