Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good ol' "Can't be instantiated"

Status
Not open for further replies.

metamorphy

Programmer
Dec 16, 2001
34
US
Im very new to java trying to compile and run a very basic threaded applet. No matter what I do, I keep getting the "class cannot be instantiated" error on Internet explorer. Can someone please show me the error of my ways.

Here's the code I am using which compiles just fine on Windows:

import java.applet.*;
import java.awt.*;

public class test extends Applet implements Runnable {


Thread t = null;


public void init() {

System.out.println("init");
}


public void destroy() {
System.out.println("destroy");
}


public void start() {
System.out.println("start(): begin");
if ( t == null ) {
System.out.println("start: creating thread");
t = new Thread( this );
t.start();
}

}


public void stop() {
System.out.println("stop");
}


public void run() {
System.out.println("run...");

/* loop to do something meaningful here... */

}


public void paint( Graphics g ) {
System.out.println("paint...");
}


}


Thanks for the help....
 
This is my first applet, but I have no problem running it in IE. My &quot;Test.class&quot; file is in the same directory as my HTML-file . (If this is not the case you have to use &quot;codebase=codebaseURL&quot; in the <applet> tag).
Maybe the problem is in the HTML page. I simple use the following :

<HTML>
<applet code=Test.class width=200 height=200>
</applet>
</HTML>

I changed the paint method to show something :
Code:
   public void paint( Graphics g ) {
      System.out.println(&quot;paint...&quot;);
      g.drawString(&quot;HelloWorld&quot;, 20, 20);
 }
PS : Where is the output from System.out.println(...) going to?
 
Its so weird. When I rebooted this morning and run the applet in IE, I get &quot;applet started&quot; instead of &quot;cannot be instantiated&quot;. All the output is showing up in the Java Console window so I guess its executing now. I did not even recompile or change any HTML code! I guess its just an Internet explorer thing. Question: Does Java console have to be enabled in IE if you want to use System.out.println()?? Maybe that was my problem....


Thanks for the help anyway.

-CH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top