Results 1 to 8 of 8
  1. #1
    java_fun2007 is offline Member
    Join Date
    Nov 2007
    Posts
    35
    Rep Power
    0

    Default Applet programs do not work in my JCreator

    Hi I fixed the path of Run Applet option in JDK Tools.
    C:\Program Files\Java\jdk1.5.0_03\bin\appletviewer.exe
    but when I compile my program it does not work I get this message on the screen.
    Exception in thread "main" java.lang.NoSuchMethodError: main

    why is that happening other main programs are working with no problem it just working with applets bring this message up.

    Java Code:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class WelcomeApplet extends JApplet
    {
    	public void init(){}
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		int xPoints[] = {-10,0,10};
    		int yPoints[] = {0,-50,0};
    		Graphics2D g2d = (Graphics2D) g;
    		GeneralPath triangle = new GeneralPath();
    		triangle.moveTo(xPoints[0],yPoints[0]);
    		for (int k = 1; k<xPoints.length;k++)
    		triangle.lineTo(xPoints[k], yPoints[k]);
    		triangle.closePath();
    		g2d.translate(200,200);
    		g2d.setColor(Color.gray);
    		g2d.fill(triangle);
    		g2d.rotate(Math.PI/4.0);
    		g2d.fill(triangle);
    		g2d.rotate(Math.PI/4.0);
    	}
    }
    the code is right, it doesn't have a problem I guess.:rolleyes:

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The error message means that the jvm (java virtual machine) cannot find a main method in the WelcomeApplet class. To run an applet from/at the prompt you need to add an applet tag in a comment to the source file, eg,
    Java Code:
    //  <applet code="WelcomeApplet" width="400" height="400"></applet>
    import java.awt.*;
    ...
    and you run it at the prompt with
    Java Code:
    currentDirectory>appletviewer WelcomeApplet.java

  3. #3
    java_fun2007 is offline Member
    Join Date
    Nov 2007
    Posts
    35
    Rep Power
    0

    Default

    I see :) thanks hardwired .. It is still not working I got an error in prompt too.
    I wrote: appletviewer WelcomeApplet.java
    the error message is " 'appletviewer' is not recognized as an internal or external command , operable program or batch file.

    I wrote this line in my program
    //<applet code="WelcomeApplet" width="400" height="400"></applet>
    above the import statements.
    Last edited by java_fun2007; 05-02-2008 at 01:03 AM.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Sounds like your computer cannot find your sdk/jdk path.
    It should probably be
    "C:\Program Files\Java\jdk1.5.0_03\bin"
    to give access to everything: javac, java and appletviewer.
    Try
    Java Code:
    currentDirectory>java -version
    to see if you get your jre version.

  5. #5
    java_fun2007 is offline Member
    Join Date
    Nov 2007
    Posts
    35
    Rep Power
    0

    Default

    this is what I got when I typed
    Java Code:
    java -version
    java version "1.6.0_05"
    java <TM> SE Runtime Environment<build 1.6.0_05-b13>
    java Hotspot <TM> Client VM <build 10.0-b19, mixed mode, sharing>

    they are different right? it should be 1.5.0_03
    Last edited by java_fun2007; 05-02-2008 at 04:23 PM.

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    You are using the latest version, 1.6.0_05, okay.
    I don't know anything about JCreator or how it sets its path variable but that seems to be the issue.

  7. #7
    java_fun2007 is offline Member
    Join Date
    Nov 2007
    Posts
    35
    Rep Power
    0

    Default

    Maybe the problem is with my computer, because I can't see applets on websites either. My IE always stuck when I visit those websites. However, I downloaded java and installed it several times.

  8. #8
    Kakuzoo is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by java_fun2007 View Post
    Hi I fixed the path of Run Applet option in JDK Tools.
    C:\Program Files\Java\jdk1.5.0_03\bin\appletviewer.exe
    but when I compile my program it does not work I get this message on the screen.
    Exception in thread "main" java.lang.NoSuchMethodError: main

    why is that happening other main programs are working with no problem it just working with applets bring this message up.

    Java Code:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class WelcomeApplet extends JApplet
    {
    	public void init(){}
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		int xPoints[] = {-10,0,10};
    		int yPoints[] = {0,-50,0};
    		Graphics2D g2d = (Graphics2D) g;
    		GeneralPath triangle = new GeneralPath();
    		triangle.moveTo(xPoints[0],yPoints[0]);
    		for (int k = 1; k<xPoints.length;k++)
    		triangle.lineTo(xPoints[k], yPoints[k]);
    		triangle.closePath();
    		g2d.translate(200,200);
    		g2d.setColor(Color.gray);
    		g2d.fill(triangle);
    		g2d.rotate(Math.PI/4.0);
    		g2d.fill(triangle);
    		g2d.rotate(Math.PI/4.0);
    	}
    }
    the code is right, it doesn't have a problem I guess.:rolleyes:

    Instead of that try this
    /*
    <applet code="WelcomeApplet" height=400 width=400>
    </applet>
    */

    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class WelcomeApplet extends JApplet
    {
    public void init(){}
    public void paint(Graphics g)
    {
    super.paint(g);
    int xPoints[] = {-10,0,10};
    int yPoints[] = {0,-50,0};
    Graphics2D g2d = (Graphics2D) g;
    GeneralPath triangle = new GeneralPath();
    triangle.moveTo(xPoints[0],yPoints[0]);
    for (int k = 1; k<xPoints.length;k++)
    triangle.lineTo(xPoints[k], yPoints[k]);
    triangle.closePath();
    g2d.translate(200,200);
    g2d.setColor(Color.gray);
    g2d.fill(triangle);
    g2d.rotate(Math.PI/4.0);
    g2d.fill(triangle);
    g2d.rotate(Math.PI/4.0);
    }
    }

    And save this as WelcomeApplet.html file.
    Now run this. It will definitely work. Believe it

Similar Threads

  1. Applet with JCreator
    By baltimore in forum Java Applets
    Replies: 2
    Last Post: 04-18-2009, 01:40 PM
  2. Will this applet ever work?
    By willemjav in forum Java Applets
    Replies: 4
    Last Post: 04-20-2008, 06:40 PM
  3. I need a simple programs
    By mikau in forum New To Java
    Replies: 2
    Last Post: 02-11-2008, 04:37 AM
  4. why doesn't this short applet work?
    By kim85 in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 09:43 PM
  5. Problem while executing programs
    By bks504 in forum New To Java
    Replies: 10
    Last Post: 08-02-2007, 02:32 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
  •