Programming help (applets in crimson editor)

  • Thread starter Thread starter fletchersally
  • Start date Start date
  • Tags Tags
    Programming
AI Thread Summary
The user is encountering a "NoSuchMethodError: main" when trying to run a Java applet code in Crimson Editor. The error indicates that the code is being executed as a standalone application rather than as an applet, which does not require a main method. To run the applet correctly, it should be embedded in a web page or executed using a development environment that supports applet execution. Some users suggest switching to other editors like Notepad++ for better functionality. The discussion highlights the importance of understanding how applets operate within a web context.
fletchersally
Messages
2
Reaction score
0
Completely new to this and having some trouble with the following code...

I'm trying to run this code in Crimson editor:
Code:
import java.awt.*; 
import javax.swing.JApplet; 

public class Snowman extends JApplet { 
    public void paint (Graphics g) { 
        final int MID = 150; 
        final int TOP = 50; 
        setBackground(Color.CYAN); 
        g.setColor(Color.BLUE); 
        g.fillRect(0, 175, 300, 50); 
        g.setColor(Color.YELLOW); 
        g.fillOval(-40, -40, 80, 80); 
        g.setColor(Color.WHITE); 
        g.fillOval(MID-20, TOP, 40, 40); 
        g.fillOval(MID-35, TOP+35, 70, 50); 
        g.fillOval(MID-50, TOP+80, 100, 60); 
        g.setColor(Color.BLACK); 
        g.fillOval(MID-10, TOP+10, 5, 5); 
        g.fillOval(MID+5, TOP+10, 5, 5); 
        g.drawArc(MID-10, TOP+20, 20, 10, 190, 160); 
        g.drawLine(MID-25, TOP+60, MID-50, TOP+40); 
        g.drawLine(MID+25, TOP+60, MID+55, TOP+60); 
        g.drawLine(MID-20, TOP+5, MID+20, TOP+5); 
        g.fillRect(MID-15, TOP-20, 30, 25); 
    }   
}

but keep getting this error:


---------- Capture Output ----------
> "C:\Program Files (x86)\Java\bin\java.exe" Snowman
java.lang.NoSuchMethodError: main
Exception in thread "main"
> Terminated with exit code 1.

and I have no idea why!

Any help is greatly appreciated!
Thanks in advance.
 
Last edited by a moderator:
Physics news on Phys.org
Latest stable release is already 6 years old, it is rather miracle it works at all. After fighting problems (unrelated to java macros) I switched to Notepad++.
 
fletchersally: Notice how I edited your post. Your code now looks like code. Use the code tags for code. You can either type them in manually or you can select a bunch of text and click on the code icon, the icon formed by a white box with its upper right corner torn off and with a # symbol inside.

Your code is also indented. There are number of different indentation schemes. Arguing which one is "right" starts religious wars amongst programmers. However, almost all programmers will agree that flush left is not "right".

java.lang.NoSuchMethodError: main
The error message is telling you that you don't have a main function. You need to have a main.
 
D H said:
The error message is telling you that you don't have a main function. You need to have a main.

You don't need a main() function in an applet. Your code looks OK (but I haven't tested it!)

What the error message really means is that you are trying to run your code as a stand-alone program, not as an applet.

Some Java development systems have a "run as applet" option that simulates the way an applet is meant to start running from inside a web page. (I don't know if the Crimson editor can do that, or how to do it). Otherwise, you will have to create a simple web page that displays the applet, and open the page in your web browser.
 
Thanks for that DH, still learning how to use this website also, and yes AlephZero I don't think Crimson can, so I'm using dos. Thanks!
 

Similar threads

Replies
4
Views
5K
Replies
0
Views
325
Replies
5
Views
3K
Replies
4
Views
2K
Replies
1
Views
5K
Replies
6
Views
3K
Replies
4
Views
3K
Replies
19
Views
1K
Back
Top