Results 1 to 17 of 17
  1. #1
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default [SOLVED] I can't run my first applet!!

    Hi!!! I'm a REAL beginner and just stumbled upon my first problem :(

    I have this code in a applet with extension .java and when I try to run the HTML file that uses the compiled file of this applet´s class I get this error:

    the class HelloAgainApplet.class> does not exist (I'm translating the real message into English for you to understand it.)
    As well as: java.lang.ClassNotFoundException: HelloAgainApplet.class>

    THANKS for your comments/help

    APPLET:

    import java.awt.Graphics;
    import java.awt.Font;
    import java.awt.Color;
    public class HelloAgainApplet extends java.applet.Applet{

    Font f = new Font("TimesRoman", Font.BOLD, 36);

    public void paint(Graphics g){
    g.setFont(f);
    g.setColor(Color.red);
    g.drawString("Hello again!", 5, 25);
    }
    }

  2. #2
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    do u have the .class file in the same directory as ur html file???

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Compile the Java code

    Once you have the .java file ready, you have to compile it to convet it into a .class file before it will run.

    Trail: Getting Started (The Java™ Tutorials)
    Compiling and Running the Examples: FAQs (The Java™ Tutorials)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Question files

    I only have these files and in the same directory
    HelloAgainApplet.java(Java-file)
    HelloAgainApplet.class(CLASS-file)
    HelloAgainApplet.html(Firefox.-doc)

    -------
    Am I supposed to have another file to run the applet???
    When I did the first example in the book I had these 5 files:

    1-HelloWorld.java(JAVA-file)
    2-HelloWorld.class(CLASS-file)
    3-HelloWorldapplet.java(JAVA-file)
    4-HelloWorldapplet.class(CLASS-file)
    5-HelloWorld.html(firefox-doc)

  5. #5
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default i have these ones

    I only have these ones.

    Quote Originally Posted by AlejandroPe View Post
    I only have these files and in the same directory
    HelloAgainApplet.java(Java-file)
    HelloAgainApplet.class(CLASS-file)
    HelloAgainApplet.html(Firefox.-doc)

    -------
    Am I supposed to have another file to run the applet???
    When I did the first example in the book I had these 5 files:

    1-HelloWorld.java(JAVA-file)
    2-HelloWorld.class(CLASS-file)
    3-HelloWorldapplet.java(JAVA-file)
    4-HelloWorldapplet.class(CLASS-file)
    5-HelloWorld.html(firefox-doc)

  6. #6
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default

    CJSLMAN.
    I did compile my java file and I have the class of that file. It happens now that it seems that I´m missing one or two files. Do I need anything else to run my applet?

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Who's on first?

    Did your first applet run (HelloWorldApplet.class)? or is the HelloAgainApplet.class your first applet?
    A couple of things:
    • Always post all code and complete error msgs. If the code is too long, then a sample code is perfered.
    • There is a subforum specific to Java applets were this might get more exposure.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default

    Yes, my HelloWorldApplet (my first applet) did run. Not the second (HelloAgainApplet).

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    OK... so it's not the installation of the JDK. Let's see the code of the .java file and the .html.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #10
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default

    //my code (.java)
    import java.awt.Graphics;
    import java.awt.Font;
    import java.awt.Color;
    public class HelloAgainApplet extends java.applet.Applet{

    Font f = new Font("TimesRoman", Font.BOLD, 36);

    public void paint(Graphics g){
    g.setFont(f);
    g.setColor(Color.red);
    g.drawString("Hello again!", 5, 25);
    }
    }

  11. #11
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default

    // and my html

    <HTML>
    <HEAD>
    <TITLE>Another Applet</TITLE>
    </HEAD>
    <BODY>
    <P>My second Java Applet says:
    <APPLET CODE ="HelloAgainApplet.class>" WIDTH=200 HEIGHT=50>
    </APPLET>
    </BODY>
    </HTML>

  12. #12
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default and this

    I see that there's no file with:

    public static void main(String args[])

    Do I need a Java application for this applet to run?

  13. #13
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    Quote Originally Posted by AlejandroPe View Post
    I see that there's no file with:

    public static void main(String args[])

    Do I need a Java application for this applet to run?
    No u dont need "main" for the applet..

    delete ">" after .class

    <APPLET CODE ="HelloAgainApplet.class>" WIDTH=200 HEIGHT=50>

  14. #14
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by tomiu View Post
    No u dont need "main" for the applet..

    delete ">" after .class

    <APPLET CODE ="HelloAgainApplet.class>" WIDTH=200 HEIGHT=50>
    Actually you don't need main method for any applet because main method is for applications with JFrame and so on. You need init(){} method instead of main(){}
    )))

  15. #15
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default

    Thanks, I'll try again.

  16. #16
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Default a "<" that got lost

    Thanks Webuser! it was an ">" that caused this error, just as Tomiu said!
    thank everyone!!:o

  17. #17
    AlejandroPe's Avatar
    AlejandroPe is offline Member
    Join Date
    Mar 2009
    Posts
    37
    Rep Power
    0

    Thumbs up Closing

    :) Thanks ROMIU!!
    I´m closing this thread after this.

    Alex

Similar Threads

  1. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 01:54 PM
  2. need applet help !
    By fadiRU in forum Java Applets
    Replies: 2
    Last Post: 02-08-2009, 03:29 AM
  3. Applet in a GUI
    By serfster in forum New To Java
    Replies: 1
    Last Post: 06-13-2008, 12:09 AM
  4. First Applet HELP????
    By nvidia in forum New To Java
    Replies: 0
    Last Post: 08-13-2007, 11:11 PM
  5. Replies: 4
    Last Post: 06-08-2007, 07:15 AM

Posting Permissions

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