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

Thread: NoSuchMethodError

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Unhappy NoSuchMethodError

    Ok, I have a main method, but it can't find it!

    I'm getting:

     

    java.lang.NoSuchMethodError: main
    Exception in thread "main"




    My code is my really big program which I've posted several times. I'm worried that it's because more than one class in a package or a project might have a main method and it might be confused. Would that confuse it, having more than one class with a main method in the same package or project?

    I've no clue whatsoever.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: NoSuchMethodError

    Are you sure the class you are trying to run has a main method?

    	public static void main(String[] args) {
     
     
    	}

    If it does? Paste the code here?!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

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

    javapenguin (November 29th, 2010)

  4. #3
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: NoSuchMethodError

    You can have as many classes as you want in the same package or project with a main method. How are you attempting to run your code?

  5. The Following User Says Thank You to DavidFongs For This Useful Post:

    javapenguin (November 29th, 2010)

  6. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: NoSuchMethodError

    Hmmmmm.

    My main does throw some kind of exception as it needs to.

    Also, shat if one of my classes that I use as an object has a main method?

    I mean, if I have a class that extends JMenuBar and has a main method in the other class that also has a main method, the class that is throwing that error. Would that cause a problem?

    Yes it has a main.

    The code is too big to show. It's longer than the maximum amount of characters.

    I cut out some import statements and variable declarations, on the one that I posted, not my actual one, so it would fit.

    It's on the thread "What's going on?".

    JSourceCode might have a main method.

    Suppose it does.

  7. #5
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: NoSuchMethodError

    I will ask again, how are you attempting to run your code? (From an IDE such as eclipse? from the command line (java classNameWithMain)?)

  8. The Following User Says Thank You to DavidFongs For This Useful Post:

    javapenguin (November 29th, 2010)

  9. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: NoSuchMethodError

    Eclipse compiler.

    So probably IDE.

  10. #7
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: NoSuchMethodError

    Ok if you are using eclipse, you should be able to right click in the class file that has the main method you want to run, and choose "run as java application"

    If this doesn't work, you probably have a problem with the way you declared your main.

  11. The Following User Says Thank You to DavidFongs For This Useful Post:

    javapenguin (November 30th, 2010)

Similar Threads

  1. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  2. java.lang.NoSuchMethodError in webserice with CXF
    By jammychen in forum Java Theory & Questions
    Replies: 1
    Last Post: September 22nd, 2010, 02:56 PM
  3. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM