java.lang.ClassCastException

Hello

this is my error:

java.lang.ClassCastException: hello cannot be cast to java.applet.Applet

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

The following is my HTML code:

<html>

<applet code = "hello.class" width = "300" height ="45">

</applet>

</html>

Here is my Java code

public class hello

{

public static void main( String args[] )

{

System.out.println("welcome to Java Programing!" );

}

}

I'm not seeing any output on the screen.

[820 byte] By [Omerona] at [2007-11-27 5:50:35]
# 1

Your browser is expecting to find an applet there. That's because you said "here is an applet", essentially, when you used the <applet> tag.

But your class does not extend java.applet.Applet, and so it is not an applet. That's the definition of an applet -- it extends java.applet.Applet.

So change that.

Also, a main() method will not be invoked by the applet. The browser expects to find an applet, and then it expects to run some standard methods that applets have, like init() and start(). Read the docs for java.applet.Applet for more info.

So you have to change what your class extends, and you have to start using normal applet methods.

paulcwa at 2007-7-12 15:38:16 > top of Java-index,Java Essentials,New To Java...
# 2
> Read the docs for java.applet.Applet for more info.And Sun's Tutorial: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html
pbrockway2a at 2007-7-12 15:38:16 > top of Java-index,Java Essentials,New To Java...
# 3
if you are in the very beginning stages of learning java i would recommend using an IDE and ignoring applets until later
lost_in_javaa at 2007-7-12 15:38:16 > top of Java-index,Java Essentials,New To Java...
# 4
Yeah, I second what the person above said. Also, I don't think System.out.println("Bla bal"); would show up in an applet, as it writes to the console.
RedUnderTheBeda at 2007-7-12 15:38:16 > top of Java-index,Java Essentials,New To Java...
# 5
> I don't think System.out.println("Bla bal"); would show up in an applet, as it writes to the console.IE has a Java console you can open to view any output. Not sure about other browsers.
floundera at 2007-7-12 15:38:16 > top of Java-index,Java Essentials,New To Java...