Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: My program will compile but wont run

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My program will compile but wont run

    Hey, basically im doing coursework to program a virtual robot to navigate its way through a maze, and im writing the code for this to happen. So, i can compile the code in the context of the maze environment, using javac -classpath maze-environment.jar MyController.java and this compiles fine and will also work okay when i add the resulting .class file to the maze environment and test it. However when i try to run the controller from the Terminal (Im on Mac OSX btw), i get the following error message:

    java -classpath maze-environment.jar MyController.java
    Exception in thread "main" java.lang.NoClassDefFoundError: MyController/java
    Caused by: java.lang.ClassNotFoundException: MyController.java
    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 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)

    Can anyone help me out with this? :/ Any help is much appreciated!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My program will compile but wont run

    Are you trying to run a jar? If so you need to use the -jar option.

    Are you trying to run a class file? If so you need to drop the .java part of the filename.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Bank Balance - while loop - wont compile
    By mwardjava92 in forum Loops & Control Statements
    Replies: 15
    Last Post: November 9th, 2011, 05:19 PM
  2. WHY WONT THIS COMPILE!
    By usmc0311 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 12th, 2011, 02:42 PM
  3. anagram program wont compile please help
    By Rusak in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 26th, 2011, 06:23 PM
  4. Anagram program wont compile
    By Rusak in forum Member Introductions
    Replies: 0
    Last Post: March 25th, 2011, 02:38 PM
  5. class wont compile
    By waspandor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2011, 04:40 PM

Tags for this Thread