Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: a applet is not working in browser(Help me i am struck'd)

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
     
    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

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: a applet is not working in browser(Help me i am struck'd)

    Sorry buddy but din work in that way....
    Still error!

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a applet is not working in browser(Help me i am struck'd)

    Still error!
    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.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
     
    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

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: a applet is not working in browser(Help me i am struck'd)

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Applet not working in Browser
    By maz3r in forum Java Theory & Questions
    Replies: 5
    Last Post: August 31st, 2012, 09:21 AM
  2. Applet isn't showing up. Perhaps it's a browser fault.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 33
    Last Post: May 14th, 2012, 08:46 PM
  3. [SOLVED] Why doesn't my Applet show up in my browser?
    By SendBorg in forum Java Applets
    Replies: 3
    Last Post: January 29th, 2012, 08:30 AM
  4. How to run Applet with Ms Sql connectivity in browser
    By mayanksmart4 in forum Java Applets
    Replies: 1
    Last Post: November 22nd, 2011, 09:57 AM
  5. HELP! My applet won't run on a web browser....
    By coolidge in forum Java Applets
    Replies: 4
    Last Post: October 21st, 2011, 08:52 AM