Results 1 to 9 of 9
  1. #1
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default ClassNotFoundException

    Hello,

    I have searched everywhere, and have not been able to find a solution that will work for me. Sorry if this is a re-post, but I couldn't find a solution.

    I am trying to create a very basic applet. I would just like it to say "hello world" on the web page, but i have been unable to do this so far.

    Here is the code i am using: (promise i do know proper naming convention, i was just trying to get this to work)

    Java Code:
    package com.FirstApplet;
    import java.applet.Applet;
    import java.awt.Graphics;
    
    public class RunApplet extends Applet{
        
        @Override
        public void paint (Graphics g)
       {
          g.drawString ("Hello World", 25, 50);
       }
    }
    XML Code:
        <head>
            <title></title>
        </head>
        <body>
            <APPLET code="RunApplet.class" width=350 height=200></APPLET>
        </body>
    </html>
    I might not understand how all this works, but I have tried everything. Thanks in advance, and sorry if I am a complete idiot!

    -Huskies
    Last edited by DarrylBurke; 08-11-2012 at 03:32 AM.

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

    Default Re: ClassNotFoundException

    Is your class in the right subdirectory according to its package name? Are you taking the package into account in the HTML code?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: ClassNotFoundException

    The class is in a package. Therefore the correct class name to use on the code= attribute should include the package name.
    The simplest solution is to remove the package statement.
    If you keep the package you need to place the class file in a folder that is in the path for the package relative to where the html file is.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: ClassNotFoundException

    When i take the Package away, it works if i run the build HTML file instead of the src HTML file. I have 2 questions:

    1: what is the difference between these two files? When i edit my HTML in NetBeans, which one am i changing?
    2: if i want to use a package, how can i specify in the path? i tried this, but it didn't seem to work.

    XML Code:
    <APPLET code="com.FirstApplet.RunApplet.class" width=350 height=200></APPLET>
    I want to point to the .class that is in the "build" folder right? sorry if these are really newbie questions, i am if you haven't guessed, quite new at all of this.

    Thanks for the quick reply!!

    Huskies

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: ClassNotFoundException

    it didn't seem to work.
    Please copy the error message from the browser's java console.

    The .class is not part of the class name for the code= attrubute.

    Using the package: com.FirstApplet the com folder should be in the same folder as the .html file.

    When i edit my HTML in NetBeans
    Sorry, I don't know how IDEs work. I use an editor.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: ClassNotFoundException

    Quote Originally Posted by Norm View Post
    The .class is not part of the class name for the code= attrubute.
    Sorry, Norm, the .class *is* required in the <APPLET code=

    This is copied from a page I have on Google Sites
    Java Code:
    <applet code = 'RedirectApplet.class' 
        archive = 'https://sites.google.com/site/.../redirectapplet.jar',
        width = 570, 
        height = 25>
        <PARAM name="codebase_lookup" value="false">
    </applet>
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: ClassNotFoundException

    .class *is* required in the <APPLET code=
    It may work sometimes and not others. I have not kept track. Have you tried it without it? I never add .class and have no problems.
    I have seen many errors where the jvm can not find a class named xxx.class. To correct the error I have the op remove the .class and it works. If the class is not found the message would say: class xxx not found.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: ClassNotFoundException

    Yay! i got it to work! I had the HTML file in the incorrect place. Thank you guys for your help!

    Also, it worked with and without the ".class" added to the end.

    Thanks again!
    Huskies

  9. #9
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: ClassNotFoundException

    Hey, sorry to ask this here, but How do I mark this as solved?! i can't seem to find the option. I know this question doesn't belong here, but I didn't want to start a completely new thread just for this. Thanks!

Similar Threads

  1. ClassNotFoundException - What jar do I need?
    By kthomp271828 in forum New To Java
    Replies: 14
    Last Post: 08-04-2011, 01:27 AM
  2. ClassNotFoundException...
    By providence in forum JDBC
    Replies: 2
    Last Post: 02-02-2011, 06:45 PM
  3. classNotFoundException
    By jyothi.priyanka in forum NetBeans
    Replies: 5
    Last Post: 08-24-2010, 10:13 AM
  4. ClassNotFoundException
    By Edward in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:08 PM
  5. ClassNotFoundException JSP
    By TDMaster in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-27-2009, 07:41 AM

Posting Permissions

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