Forum Stats

  • 3,826,580 Users
  • 2,260,667 Discussions
  • 7,897,010 Comments

Discussions

Problems with running Applet through HTML

803569
803569 Member Posts: 30
edited Nov 27, 2010 11:27PM in Java Programming
I am currently having problems with running my file through the HTML. For some reason when I open it in the browser it keeps saying Error. I am programming in NetBeans.

The code I am using is:

<html>
<head>
<title></title>
</head>
<body>
<applet code=”CarApplet.class” codebase="RedCarApplet.jar" width=690 height=300></applet>
</body>
</html>
Tagged:
«1

Answers

  • 811778
    811778 Member Posts: 87
    800566 wrote:
    I am currently having problems with running my file through the HTML. For some reason when I open it in the browser it keeps saying Error. I am programming in NetBeans.
    You literally just see 'Error' in the browser?
  • 803569
    803569 Member Posts: 30
    Yer, when I try to open the browser its a box where the Applet should be but it just says "Error Click for Details".

    Does the HTML file have to be in the same folder as the .class or .jar folder?
  • DrClap
    DrClap Member Posts: 25,479
    800566 wrote:
    Yer, when I try to open the browser its a box where the Applet should be but it just says "Error *Click for Details*".
    Didn't it occur to you to "click for details"?
  • 803569
    803569 Member Posts: 30
    Heres the error message, I see that it cannot find the class I have stated above. Any solutions?

    My class is in the 'build' folder but, the HTML file is in the 'src' folder. Now my applet contains a 'jar' file, do I need to add that to the HTML code?


    load: class ‚Ä?TunerApplet.class‚Ä? not found.
    java.lang.ClassNotFoundException: ‚Ä?TunerApplet.class‚Ä?
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\Users\*****\*******\NetBeansProjects\RadioApplet\src\‚Ä?TunerApplet\class‚Ä?.class (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 9 more
    Exception: java.lang.ClassNotFoundException: ”TunerApplet.class”
  • DrClap
    DrClap Member Posts: 25,479
    You're one of those people who are dazzled by the IDE you're working in. In real life when you deploy the applet in your web server, there isn't going to be a "src" folder or a "build" folder. Work out where to put your applet in the web server and design the HTML for that.

    As for the jar file, I think you have to use the "archive" tag to specify where that is. Bear in mind that the URLs you put in the <applet> element are relative to the HTML's base URL.
  • 803569
    803569 Member Posts: 30
    Still not working, I put the HTML in the classes folder, but it doesnt load

    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <applet code="build.classes.mymain.TunerApplet" archive="RadioApplet.jar"></applet>
    </body>
    </html>
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    edited Nov 27, 2010 6:09AM
    Then you haven't understood. Nobody said to put the HTML there. You're still doing it back to front. You have to put the JAR file along with the HTML in the same folder in the target deployment. That's the meaning of the HTML you have written. If the JAR file isn't there, or doesn't contain all the necessary classes, your applet can't run.
  • 803569
    803569 Member Posts: 30
    edited Nov 27, 2010 6:10AM
    k Thx

    Edited by: 800566 on Nov 27, 2010 3:10 AM
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    edited Nov 27, 2010 6:16AM
    And your code attribute is wrong. It must name your applet class in its package. Your applet class isn't in the package build.classes.mymain.
  • 803569
    803569 Member Posts: 30
    I figured it out, for some reason it doesn't work on Mac, but I tried it on Windows 7 and its showing now.
This discussion has been closed.