a applet is not working in browser(Help me i am struck'd)
i have made a HelloWorld applet(running in appletviewer in EclipseIDE) , now i just wanted to run it from my browser but it is not running.
code as follows.
package com.bhaveshjava.trial;
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(250,250);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 150, 100);
}
}
and htmlfile
<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="com.bhaveshjava.trial.HelloWorld" codebase="./bin" WIDTH=150 HEIGHT=255>
</APPLET>
</BODY>
</HTML>
further both the HelloWorld.class and Hello.html are in the same folder, still in browser it is showing the "Here is the output of my program:" after that an error
message.
Details of error message are provided
Java Plug-in 1.6.0_35
Using JRE version 1.6.0_35-b10 Java HotSpot(TM) Client VM
User home directory = C:\Users\bhavesh
----------------------------------------------------
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>
----------------------------------------------------
load: class com.bhaveshjava.trial.HelloWorld not found.
java.lang.ClassNotFoundException: com.bhaveshjava.trial.HelloWorld
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: com.bhaveshjava.trial.HelloWorld
a applet is not working in browser
i have made a HelloWorld applet(running in appletviewer in EclipseIDE) , now i just wanted to run it from my browser but it is not running.
code as follows.
Code java:
package com.bhaveshjava.trial;
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(250,250);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 150, 100);
}
}
and htmlfile
<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="com.bhaveshjava.trial.HelloWorld" codebase="./bin" WIDTH=150 HEIGHT=255>
</APPLET>
</BODY>
</HTML>
further both the HelloWorld.class and Hello.html are in the same folder, still in browser it is showing the "Here is the output of my program:" after that an error
message.
Details of error message are provided
Java Plug-in 1.6.0_35
Using JRE version 1.6.0_35-b10 Java HotSpot(TM) Client VM
User home directory = C:\Users\bhavesh
----------------------------------------------------
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>
----------------------------------------------------
load: class com.bhaveshjava.trial.HelloWorld not found.
java.lang.ClassNotFoundException: com.bhaveshjava.trial.HelloWorld
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: com.bhaveshjava.trial.HelloWorld
Re: a applet is not working in browser(Help me i am struck'd)
Where is the com folder?
It will be easier if you remove the package statement and have the class file(s) in the same folder with the html file.
Re: a applet is not working in browser(Help me i am struck'd)
there are two folders locations.
src/com/bhaveshjava/trial/HelloWorld.java also Hello.html is in this trial folder
bin/com/bhaveshjava/trial/HelloWorld.class also Hello.html is in this trial folder
html is located in both the places, but i am executing the one in which HelloWorld.class is located
Re: a applet is not working in browser(Help me i am struck'd)
Try removing the package statement and put all the files in the same folder.
Otherwise you must make sure the folders are in the correct locations.
Re: a applet is not working in browser(Help me i am struck'd)
Sorry buddy but din work in that way....
Still error!
Re: a applet is not working in browser(Help me i am struck'd)
Please post the full text of the error message. Also Please post the new code and html and describe where all the files are located.
Re: a applet is not working in browser(Help me i am struck'd)
the error msg generated after moving all files in same folder is as follows:
Java Plug-in 1.6.0_35
Using JRE version 1.6.0_35-b10 Java HotSpot(TM) Client VM
User home directory = C:\Users\bhavesh
----------------------------------------------------
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.NoClassDefFoundError: HelloMaster (wrong name: com/bhaveshjava/lesson5/HelloMaster)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: HelloMaster (wrong name: com/bhaveshjava/lesson5/HelloMaster)
now the code for HelloMaster.java
Code Java:
import java.awt.Graphics;
@SuppressWarnings("serial")
public class HelloMaster extends java.applet.Applet{
public void init(){
resize(450,400);
}
public void paint(Graphics g){
g.drawString("Hello Sir",200,150);
}
}
[code=html]
<html>
<head>
<title>Hello Master</title>
</head>
<body>this is the class
<BR>
<applet code="HelloMaster.class" width="600" height="600">
</applet>
</body>
</html>
[/html]
All the three files Hell.html,HelloMaster.java. HelloMaster.class are in same folder src.com.bhaveshjava.lesson5
before the HelloMaste.class was located in bin.com.bhaveshjava.lesson5 and a Hell.html file was also there with this class file in ./bin
i tried all alternatives but failed, i know there is some logical error...
but as per applet is considered , logically since before only both the class file and html page are in same folder. it is not the matter of output , it is all about logic, which i applied correctly.
Now help me if my approach is wrong
Re: a applet is not working in browser(Help me i am struck'd)
Quote:
java.lang.NoClassDefFoundError: HelloMaster (wrong name: com/bhaveshjava/lesson5/HelloMaster)
Where did that package name come from? Did you compile the source without the package statement? Make sure you are using the correct class file: the one without the package statement.
Re: a applet is not working in browser(Help me i am struck'd)
no actually if i remove the package name the code itself is not getting compiled..
but wait i got output when i kept it in a default package...
explain me why i cant put it in a package?
N really thanks for your help.
Re: a applet is not working in browser(Help me i am struck'd)
You can put it in a package. It just makes the setup for execution more complicated because all the paths and locations of files must be correct. Without a package, everything can go in one folder.