Results 1 to 10 of 10
  1. #1
    jbnaylor is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Cannot Find Main Class

    hi all,
    i'm VERY new to java. i'm enrolled in a course that is just breifly introducing us to JAVA.
    all I have to do is take a code i have been given (2, actually), compile it, and link it to a very simple HTML page.
    i have downloaded the version 6 jdk, and have compiled the files so that i now have .class files for both.
    when i try to run them, i get this:

    Exception in thread "main" java.lang.NoClassDefFoundError: Oval
    Caused by: java.lang.ClassNotFoundException: Oval
    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)
    Could not find the main class: Oval. Program will exit.

    Here is the code I have compiled and am trying to run:
    import java.awt.*;
    import java.applet.*;
    public class Oval extends Applet {
    public void paint (Graphics g) {
    Color c=new Color(20,120,160);
    g.setColor(c);
    g.fillOval(20,20,60,30);
    }
    }


    It has been saved as Oval.java, and compiled into Oval.class.
    I get the exact same message for the other file I am supposed to compile (with the file name Triangle instead of Oval, of course), so I figure its gotta be something about my installation or path settings.
    Both my Path and ClassPath values are set at "C:\Program Files\jdk1.6.0_29\bin" and nothing else.
    I am entirely turned around. My head is spinning. I have spent at least 8 hours over the last few evenings try to run these simple programs.
    This is the latest of many error messages I have received, while both attempting to compile and attempting to run the program. After uninstalling and reinstalling and retrying many different versions of Java, and changing Paths and ClassPaths.
    The only thing this course is teaching me is that I have a looooong way to go if I ever want to learn how to use Java.
    Anyways, any help would be greatly appreciated! Thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot Find Main Class

    Does your applet have an init method? I don't see one. Have you gone through an applet tutorial first before trying to code one?

  3. #3
    jbnaylor is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Cannot Find Main Class

    Hi - Thanks for the quick response
    I did not write the code myself - it was given to me. The course does not expect that of us. My assignment is just to compile it and run it, then link it to a web page.
    All I have been given is what I pasted above.
    I feel like I need weeks to learn even the most basics of this stuff, but only have a few days to get this assignment done, which is actually more about the HTML writing than the Java.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot Find Main Class

    You don't "run" an applet, not in the usual sense. It is either run from HTML code or from an applet viewer.

  5. #5
    jbnaylor is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Cannot Find Main Class

    Wow, further down the rabbit hole we go. I'm sorry, but if you could just bear with my ignorance here...
    So I compiled it by using "javac Oval.java" in the command prompt, which I assume worked because it created a .class file.
    What's my next move? I was under the impression it was to type "java Oval" or "java Oval.class" into the command prompt...although I was uncertain what is supposed to happen next - but was sure it was not supposed to give me an error message.
    I know I should probably try to learn more about this, but time restraints are causing me to have to act, not think.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot Find Main Class

    Please google for an applet tutorial which will explain all. Don't try to stumble through blind.

  7. #7
    jbnaylor is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Cannot Find Main Class

    That's fantastic. Thank you. Can't wait to return to this forum.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Cannot Find Main Class

    Another happy customer. We should have them stuffed.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot Find Main Class

    Quote Originally Posted by jbnaylor View Post
    That's fantastic. Thank you. Can't wait to return to this forum.
    If your sense of entitlement means that you won't do this work yourself, you have two choices: either I go to a tutorial, copy what they recommend and then paste it here because you are not willing to look yourself, or I try to write you a chapter on how to run applets that's better than tutorials written by professionals. Please. We are volunteers. Try to show a little effort.

  10. #10
    jbnaylor is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Cannot Find Main Class

    Absolutely no sense of entitlement here.
    Just wanted to let you know that this extremely difficult question was answered in about 17 seconds by someone else.
    Your response in #4 was right, and just what I was looking for...just needed to expand on it a little for me.
    "Where Learning and Development Begins" huh? Might want to put a footnote on that, *"after learning and developing somewhere else for a while first, 'cause we don't have the patience for you."
    Nonetheless, quick responses were much appreciated, and if I do pursue Java further I actually will be glad to use this forum again.

Similar Threads

  1. Could not find the main class:
    By Kareng in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-01-2011, 08:04 AM
  2. Could not find or load main class BubbleSort.class
    By blaqkout in forum New To Java
    Replies: 5
    Last Post: 09-12-2011, 07:54 PM
  3. Could Not Find Main Class (again)
    By illjavathat in forum New To Java
    Replies: 25
    Last Post: 11-23-2010, 09:49 AM
  4. could not find main class?
    By deathnote202 in forum New To Java
    Replies: 6
    Last Post: 05-10-2010, 08:57 PM
  5. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •