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 2 of 2

Thread: I've never seen these erros before

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I've never seen these erros before

    I am in the process of writing a code that involves buttons and a displaypanel and a lot of different things, so ive decided to Test as I go with every aspect of the code. I tried setting up just the background display with a line and two rectangles and i got errors. here is my code:
    import java.awt.*;
    import javax.swing.*;
     
    public class SaucerPanel extends JPanel{
    static final long serialVersionUID = 1;
    public SaucerPanel(){
    setPreferredSize(new Dimension(500,400));
    setBackground(Color.red);
     }
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawLine(0,380,500,380);
    g.drawRect(111,180,200,100);
    g.drawString("hovering...", 10, 15);
    }
    }

    and it compiled just fine but when i hit Run on Dr. Java I got this under the Interactions Panel
    java.lang.NoSuchMethodError: main
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at edu.rice.cs.dynamicjava.symbol.JavaClass$JavaConst ructor.evaluate(JavaClass.java:298)
    at edu.rice.cs.dynamicjava.interpreter.ExpressionEval uator.handleConstructor(ExpressionEvaluator.java:1 28)
    at edu.rice.cs.dynamicjava.interpreter.ExpressionEval uator.visit(ExpressionEvaluator.java:98)
    at koala.dynamicjava.tree.SimpleAllocation.acceptVisi tor(SimpleAllocation.java:137)
    at edu.rice.cs.dynamicjava.interpreter.ExpressionEval uator.value(ExpressionEvaluator.java:38)

    can anyone explain/help me with this


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I've never seen these erros before

    Every application in java requires a program entry point, which is the main method (see Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started)). The code you posted needs this entry point. In your case you need a bit more because the JPanel itself needs to be added to a top level container (see Using Top-Level Containers and How to Make Frames) for it to be visible.