The moose likes Beginning Java and the fly likes BasicsDemo error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BasicsDemo error message" Watch "BasicsDemo error message" New topic

BasicsDemo error message

Brent King

Joined: Apr 18, 2005
Posts: 8
public class BasicsDemo {
public static void main(String[] args) {
int sum = 0;
for (int current = 1; current <= 10; current++) {
sum += current;
System.out.println("Sum = " + sum);

The output from this program is:

Sum = 55

I compiled the following prog. and got the following message in appletviewer: applet not initialized.

This was the following message at the C Prompt:
C:\Program Files\Java>appletviewer BasicsDemo.html
java.lang.ClassCastException: BasicsDemo
at sun.applet.AppletPanel.createApplet(
at sun.applet.AppletPanel.runLoader(

Thanks Brent
Henry Wong

Joined: Sep 28, 2004
Posts: 20514

Appletviewer is used to run/test Applets. Your program is not an Applet. You are getting a cast exception because your class do not extend the java.applet.Applet class.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Brent King

Joined: Apr 18, 2005
Posts: 8
Sorry I am getting application and applet mixed up.
I agree. Here's the link:
subject: BasicsDemo error message
It's not a secret anymore!