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 12 of 12

Thread: Java applet

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

    Default Java applet

    Hello,
    I have a problem when I try to implement java applet to a web page. Web page keeps saying :
    NoClassDefFoundError. Can anyone help me with this?

    here is a html code:

    HTML Code:
    <header>
    
    <body>
    
    <applet code = "Calculator.class" width=300 height=250 />
    
    </body>
    
    </header>


  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: Java applet

    Don't add the .class part. It's like when you run a Java class file, you don't say "java ClassName.class" - you just do "java ClassName".

    Recommended reading: Deploying With the Applet Tag (The Java™ Tutorials > Deployment > Java Applets)
    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!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    ikocijan (June 29th, 2012)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java applet

    Please post the full text of the error message so we know what the full problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ikocijan (July 3rd, 2012)

  6. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java applet

    Removing .class didn`t help.

    when I launch .html file chrome should display my calculator (eclipse displays it as an applet). I attached screen shoot. hope that helps.error.JPG

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java applet

    If your class is in a package, you must include the package name with the class name.
    See the error message for the full classname that includes the packagename.
    I can't select and copy from an image so you will have to see the full name for yourself.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    ikocijan (June 29th, 2012)

  9. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java applet

    do you mean something like this:
    HTML Code:
    <applet code = "com/PracticalJava/Lesson10/Calculator" width=300 height=250 />
    I tried that and I got error: ClassNotFoundException

    I made a simple program so that I am sure that everything works(used default package):

                 public class HelloWorld extends JApplet {
    		public void paint (Graphics g){
    			g.drawString ("Hello World", 50, 100);
    		}	
    }

    and then I made a html:

    HTML Code:
    <html>
             <body>
    
    <applet code = "HelloWorld" width=300 height=250/>
    
            </body>
           </html>
    Everthing works in Ecplise but Chrome shows ClassNotFoundException:


    error.JPG

    I tried with HelloWorld.class and only HelloWorld

  10. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java applet

    I got error: ClassNotFoundException
    Please copy the full text of the error message and paste it there.
    You can get the error message from the browser's java console.

    I can not copy text from an image to show what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    ikocijan (July 3rd, 2012)

  12. #8
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java applet

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it there.
    You can get the error message from the browser's java console.

    I can not copy text from an image to show what the problem is.
    Well that is going to be a problem because I can not copy anything from that window. In chrome when I launch web page only that window pop- up and if I press Details it opens Java consoe. If I press Ignore program still won`t load and if I press Reload window pop- up again. I wish I could give you more but that is the only thing that happens.

  13. #9
    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: Java applet

    Please read the tutorial I posted, it addresses all of your issues. Hint: how do you separate packages?
    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!

  14. The Following User Says Thank You to KevinWorkman For This Useful Post:

    ikocijan (June 30th, 2012)

  15. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java applet

    if I press Details it opens Java console
    The Java console has a button for copying its contents.
    If you don't understand my answer, don't ignore it, ask a question.

  16. The Following User Says Thank You to Norm For This Useful Post:

    ikocijan (June 30th, 2012)

  17. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java applet

    Thank you for your replies. I will read the tutorial later today and try java console.

  18. #12
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Java applet

    I read all about creating and working with jar files and now everything works. Thank you guys for wasting your time on my problem

Similar Threads

  1. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  2. Need help with Java applet
    By Trendle in forum Java Applets
    Replies: 0
    Last Post: May 18th, 2012, 11:30 AM
  3. My first java applet
    By Fathermucker in forum Java Applets
    Replies: 2
    Last Post: April 4th, 2012, 01:26 PM
  4. Java Applet
    By Ludicrous in forum Java Applets
    Replies: 7
    Last Post: March 31st, 2012, 02:40 PM
  5. Need help with java applet game.
    By vlan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 10th, 2010, 04:18 AM