7 Replies - 2270 Views - Last Post: 27 February 2011 - 07:53 PM Rate Topic: -----

#1 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Simple Hello World program not working.

Posted 27 February 2011 - 02:42 AM

First of all, here is my source.

public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello World");
	}//End of main
}//End of HelloWorld Class



It compiles and runs, but when I try to load it as an applet I get this error message.

Java Plug-in 1.6.0_24
Using JRE version 1.6.0_24-b07 Java HotSpot(TM) Client VM
User home directory = C:\Users\Trea
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
 
 
java.lang.reflect.InvocationTargetException
        at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager.runOnEDT(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.lang.ClassCastException: HelloWorld cannot be cast to java.applet.Applet
        at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.reflect.InvocationTargetException



What am I doing wrong? :(

This post has been edited by LegalBreaker: 27 February 2011 - 02:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Simple Hello World program not working.

#2 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: Simple Hello World program not working.

Posted 27 February 2011 - 03:05 AM

Read this tutorial: http://download.orac...plet/index.html
Was This Post Helpful? 1
  • +
  • -

#3 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Re: Simple Hello World program not working.

Posted 27 February 2011 - 12:08 PM

So you really need to use those fancy libraries and classes to get an applet to work? Disappointing..
Was This Post Helpful? 0
  • +
  • -

#4 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Simple Hello World program not working.

Posted 27 February 2011 - 12:33 PM

You've created a simple command line hello world program which is not an applet. To create an Applet, look at the link mi14chal provided for you.
Was This Post Helpful? 0
  • +
  • -

#5 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Re: Simple Hello World program not working.

Posted 27 February 2011 - 12:36 PM

I did and I got it working I'm just asking if it's really this much more complex to make an applet versus a command line program.
Was This Post Helpful? 0
  • +
  • -

#6 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Simple Hello World program not working.

Posted 27 February 2011 - 12:43 PM

Well Applets are a little more work since you are dealing with a GUI environment. Command line programs aren't and you simply print to the console for displaying text.

Have a look at macosxnerd101's Getting Better at Programming (Java) thread to see parts you should be covering at each level. :)
Was This Post Helpful? 2
  • +
  • -

#7 LegalBreaker  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 25-June 09

Re: Simple Hello World program not working.

Posted 27 February 2011 - 07:31 PM

Awesome, thanks!
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Simple Hello World program not working.

Posted 27 February 2011 - 07:53 PM

Just to calm a bit your impatience you can try that one :)


import javax.swing.*;

public class HelloWorld extends JApplet {

	JLabel label;
	
	public void init() {
		label = new JLabel("Hello World");
		add(label);
	}
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1