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

Thread: main error

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default main error

    I've written code to draw a rectangle. I'm pretty sure i did everything right. This is my code:

    package hmm;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Hmm {
    private static class drawrectangle extends JPanel {
        public void paintComponent(Graphics g) {
        super.paintComponent(g);
                g.drawRect(50, 50, 50, 50);
    }
    }
     
        public static void main(String[] args) {
          drawrectangle displayPanel = new drawrectangle();
          JPanel content = new JPanel();
          content.add(displayPanel);
          JFrame window = new JFrame();
          window.setContentPane(content);
          window.setVisible(true);
        }
    }

    However whenever i try to run it i get this error:
    "java.lang.NoSuchMethodError: main
    Exception in thread "main" Java Result: 1"

    I'm don't know what this means. Also, I compiled this code using NetBeans IDE.


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: main error

    I compiled your code and it is working.
    restart your IDE
    sometimes helps!
    give a backgroud color to differ your panels.

  3. The Following User Says Thank You to serdar For This Useful Post:

    Shivam24 (August 29th, 2011)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: main error

    What happens if you open a command prompt, change to the folder with the Hmm.class file and enter:
    java Hmm

  5. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: main error

    all i needed to was restart the IDE. Thanks

  6. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: main error

    Restarting the IDE may not have been necessary. Doing a clean and build might have resolved the problem.
    Improving the world one idiot at a time!

Similar Threads

  1. Need Help with main arg for the project
    By Nightmare in forum Collections and Generics
    Replies: 4
    Last Post: November 30th, 2010, 02:40 PM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. main methos problem
    By bondage in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 1st, 2010, 02:43 AM
  4. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM
  5. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM