LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Java applet error: "Applet Failed" (http://www.linuxquestions.org/questions/programming-9/java-applet-error-applet-failed-223632/)

nro 08-28-2004 04:36 PM

Java applet error: "Applet Failed"
 
First, here is my code:

Code:

import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class firstApplet extends java.applet.Applet {
   
    Font f = new Font("TimesRoman",Font.BOLD,36);
   
    public void paint(Graphics g) {
        g.setFont(f);
        g.setColor(Color.red);
        g.drawString("Hello World", 5, 50);
    }
}

and my HTML file:


Code:

<HTML>
<HEAD>
  <TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>

<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

<P>
<APPLET codebase=.. code="firstApplet.class" width=350 height=200></APPLET>
</P>

<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>

I have been struggling to get my java applets to load. I eventually got the plugin installed correctly in Konqueror(I used to get a message saying the java plugin wasn't initialized), but now I am not able to load my applets.

I tried a second method to view the applets, I used the "appletviewer" that comes with the java SDK. Here is my out put:

[mike@localhost firstApplet]$ appletviewer firstApplet.html
java.lang.NoClassDefFoundError: firstApplet/firstApplet (wrong name: firstApplet)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:157)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:561)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
at sun.applet.AppletPanel.run(AppletPanel.java:298)
at java.lang.Thread.run(Thread.java:534)

The appletviewer does appear, but at the bottom it says "Start: applet not initialized".

If you know of a seperate program that can view applets outside a browser's plugins, I would be more than happy to hear about it.

All help is always appreciated :-)

Thanks,
Mike

jlliagre 08-28-2004 05:52 PM

appletviewer worked for me with both your applet and html only after I replaced codebase=.. by codebase="."


All times are GMT -5. The time now is 12:49 AM.