Results 1 to 8 of 8
  1. #1
    deapee is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default Error when trying to view applet in a .htm file

    So as you can see I'm kind of new to this whole thing. I'm using eclipse IDE. I wrote my program just fine, ran it, and it printed "Hello World" in the output box...

    My .htm file and my .class file are both located on the desktop (so same folder)...

    I must be missing something obvious, please help...Thanks.

    Java Code:
    public class firstjava {
    	public static void main(String[] args) {
    	System.out.println("Hello World!");
    	}
    }
    Then my HTML file:

    Java Code:
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    
    <table cellpadding="5" bgcolor="#FF0000">
    <tr>
    <td>
    <APPLET CODE="firstjava.class" WIDTH="400" HEIGHT="200">
    </APPLET></td>
    </tr>
    </table> 
    
    </BODY>
    </HTML>

    And the error I get:

    Java Plug-in 1.6.0_26
    Using JRE version 1.6.0_26-b03 Java HotSpot(TM) Client VM
    User home directory = C:\Users\deep
    ----------------------------------------------------
    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(Un known Source)
    at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown 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)
    Caused by: java.lang.ClassCastException: firstjava 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.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(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
    Other applets on the web seem to be working fine. Thanks again.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    For starters firstjava is not an Applet.

  3. #3
    deapee is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    I thought that to include it on the webpage, you simply did what I did with the .class file and it would do it's thing?

    In fact I can compile the .java file fine in command prompt too...then when I run:

    "java firstjava"

    I get this error:


  4. #4
    deapee is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Alright well I don't know what the problem was but I got it to work using this code for the .java:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class firstjava extends JApplet {
    
    public void paint(Graphics g) {
    	super.paint(g);
    	g.drawString("does this work???", 25, 25);
    }
    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You don't want to borrow code without understanding it. Have you gone through the applet tutorials yet? If not, then you might want to do so.

  6. #6
    deapee is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    No, but I wanted to be certain that I understood how to properly compile stuff, that I had my environment variables set up properly, and that I knew how to properly put an applet on a web page before I started learning about syntax or going through any tutorials.

    I'm completely unfamiliar with java, but am somewhat familiar with c and c++, and pretty proficient with vb.

    I definitely plan on checking out the tutorials at some point here shortly. Thanks.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    But if you go through an Applet tutorial it will explain all that to you.

  8. #8
    deapee is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    I already had all that written and I was not sure why it wasn't working before I found the site here. Only found the site because I was searching for a forum to ask about that.

    Link to said tutorials pls :D

    EDIT: I probably got off on the wrong foot with you guys lol. I plan on getting a book and following tutorials and everything...just wanted to make sure I understood the process from .java to .class to viewable on a webpage before I get into learning the syntax and the important details. I like to visualize stuff and I would honestly have a hard time sitting through the 'boring' stuff until I actually saw something in action.
    Last edited by deapee; 06-20-2011 at 04:58 AM.

Similar Threads

  1. how to view a file from vss through java code
    By sireesha264 in forum Advanced Java
    Replies: 4
    Last Post: 07-23-2008, 12:06 PM
  2. Applet - enter URL and view the page
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:38 PM
  3. Unable to view japanese in java applet
    By rogermakrm in forum Java Applets
    Replies: 5
    Last Post: 01-16-2008, 06:07 AM
  4. How to view applet from html page.
    By jwzumwalt in forum Java Applets
    Replies: 2
    Last Post: 11-24-2007, 04:21 AM
  5. To turn a view jsp to a pdf file
    By Daniel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 06:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •