Results 1 to 6 of 6
- 12-30-2010, 10:15 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 7
- Rep Power
- 0
runtime error 'could not find main class' ?
I want to write a simple console application showing the content of two object instances. Following code compiles without error however gives the following runtime error : 'could not find the main class: ConsoleApplication.KlantType. Program will exit.'
If I 'clean an build project' (Netbeans) then I get
Created dir: D:\Java\NetBeansProjects\ConsoleApplication1\dist
Not copying the libraries.
Building jar: D:\Java\NetBeansProjects\ConsoleApplication1\dist\ ConsoleApplication1.jar
To run this application from the command line without Ant, try:
java -jar "D:\Java\NetBeansProjects\ConsoleApplication1\dist \ConsoleApplication1.jar"
jar:
BUILD SUCCESSFUL (total time: 1 second)
If I do that I get following error message on the dos prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: consoleapplication1/M
ain
Caused by: java.lang.ClassNotFoundException: consoleapplication1.Main
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: consoleapplication1.Main. Program will exit.
What is wrong? How to solve?
Here's the code:
package ConsoleApplication1;
public class KlantType {
private String Naam;
public KlantType(String naam) {
Naam = naam;
}
public void setNaam(String value) {
Naam = value;
}
public String getNaam() {
return Naam;
}
private static String klantNaam;
public static void main(String[] args) {
KlantType klantObjectInstance1 = new ConsoleApplication1.KlantType("Janssen");
KlantType klantObjectInstance2 = klantObjectInstance1;
klantObjectInstance2.setNaam("Pietersen");
System.out.println("Waarden na toekenning waarde Pietersen aan eigenschap Naam van instance klant2 van Object Klant");
klantNaam = klantObjectInstance1.getNaam();
System.out.println("Klant 1 : " + klantNaam);
klantNaam = klantObjectInstance2.getNaam();
System.out.println("Klant 2 : " + klantNaam);
}
}Last edited by ruud00000; 12-30-2010 at 11:14 PM.
- 12-30-2010, 11:22 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 13
- Rep Power
- 0
Add "public static void main(String [ ] args){}"
You need a main class for the applet to run.
- 12-30-2010, 11:36 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 7
- Rep Power
- 0
That's already there ?
See line just above
KlantType klantObjectInstance1 = new ConsoleApplication1.KlantType("Janssen");
KlantType klantObjectInstance2 = klantObjectInstance1;
klantObjectInstance2.setNaam("Pietersen");
System.out.println("Waarden na toekenning waarde Pietersen aan eigenschap Naam van instance klant2 van Object Klant");
klantNaam = klantObjectInstance1.getNaam();
System.out.println("Klant 1 : " + klantNaam);
klantNaam = klantObjectInstance2.getNaam();
System.out.println("Klant 2 : " + klantNaam);
- 12-31-2010, 12:11 AM #4
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
You are trying to run a class namned “consoleapplication1.Main”, you
should run “ConsoleApplication1.KlantType”.Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 12-31-2010, 08:42 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 7
- Rep Power
- 0
Well actually I just do what NetBeans suggests: at the command prompt I enter
java -jar "D:\Java\NetBeansProjects\ConsoleApplication1\ dist \ConsoleApplication1.jar"
On the other hand if I go to the file KlantType.java in the NetBeans navigator, right click and chose to run the file directly it works well.
Can I also run this KlantType.java file directly from the command prompt (Windows). How exactly?
If I open the file in JavaEditor instead of NetBeans and run it from there I get the following error message in the DOS window. Note that now it DOES try to open the correct (public) class 'ConsoleApplication1.KlantType', however it fails to run:
Exception in thread "main" java.lang.NoClassDefFoundError: ConsoleApplication1/K
lantType
Caused by: java.lang.ClassNotFoundException: ConsoleApplication1.KlantType
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
Could not find the main class: ConsoleApplication1.KlantType. Program will exit
- 12-31-2010, 05:58 PM #6
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Similar Threads
-
Error: Could Not Find Main Class. Program Will Exit
By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM -
jar file ERROR:Could not find the main class. program will exit.
By Himanshu23 in forum AWT / SwingReplies: 3Last Post: 11-11-2010, 08:12 AM -
[SOLVED] Could not find the main class: error...
By bobleny in forum New To JavaReplies: 21Last Post: 03-02-2010, 10:53 AM -
could not find main class, the program wil exit-- error in jar file
By nishant.4545 in forum Advanced JavaReplies: 1Last Post: 07-03-2009, 08:41 PM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks