13 Replies Latest reply: Oct 30, 2008 5:32 AM by 843785 RSS

    java.lang.NoSuchMethodError: main

    843785
      Sometimes i got this error when working

      --------------------Configuration: <Default>--------------------
      java.lang.NoSuchMethodError: main
      Exception in thread "main"
      Process completed.

      I have worked with containers for some time (i am still learning) and now i work with exceptions. I have looked over other posts but found nothing interesting.
      This is the code:

      public class Solar{
      public void f() throws SolarException{
      System.out.println("Throw SolarException from Solar.");
      throw new SolarException();
      }
      public static void main(String[] args){
      Solar solar = new Solar();
      try{
      solar.f();
      } catch(SolarException se){
      System.out.println("Caught it!");
      }
      }
      }
      class SolarException extends Exception{
      }

      Now, i now a solution from before, change "public static void main(String[] args)" line into "public static void main(java.lang.String[] args)"and it works.
      I do not have any clue why this is happening. CLASSPATH is set. The editor i use is JCreator, and CLASSPATH is set under Configure->Options->JDK Profiles.
      So any idea why is this happening. Also the class name is Solar.

      Also putting:

      import java.lang.String;

      eliminates the problem, but i did not have to use this earlier.

      And one more thing: on previous version of JCreator when i got this message, i just scrolled main method to be visible on the screen, marked it with mouse and it worked. Belive me! I know it is stupid, i myself couldnt belive it.

      Edited by: Martin.Berger on Oct 29, 2008 4:07 PM
        • 1. Re: java.lang.NoSuchMethodError: main
          843785
          It sounds like you have some kind of config problem with JCreator. I tried your code in both Eclipse, and SciTE and got the following:
          SciTE:
          Throw SolarException from Solar.
          Caught it!
          Eclipse:
          Throw SolarException from Solar.
          Caught it!
          Sorry I can't help more specifically, but it must be something about the way you have JCreator setup.
          • 2. Re: java.lang.NoSuchMethodError: main
            843785
            Now, i now a solution from before, change "public static void main(String[] args)" line into "public static void main(java.lang.String[] args)"and it works.
            That means String is not interpreted as java.lang.String. You defined a class named String in this project. Not a good idea. Delete your String.java and Styring.class and try again.
            • 3. reply
              843785
              RRPeter ~ i do not know what it could be.
              BigDaddyLoveHandles ~ sorry, i am missing your point. I do not have String class. About what are you telling me?
              • 4. Re: reply
                843785
                I think you defined a class and named it String. Take a look in your folder.
                • 5. Re: reply
                  796447
                  BigDaddyLoveHandles wrote:
                  I think you defined a class and named it String. Take a look in your folder.
                  @Martin.Berger - I strongly concur. I am positive based on the evidence that you do in fact have a home-grown "String" class getting in the way of things.
                  • 6. Re: reply
                    843785
                    bigdaddy & warnerja ~ yes, i have four such classes. String, String12, String2, String2222. What are those? I have never made those.
                    • 7. Re: reply
                      843785
                      At night, elves download pr0n onto my machine. Maybe you have Nerd Elves.
                      • 8. Re: reply
                        843785
                        If you have String,String12.... as seperate classes for different purpose which is not good practise you have to import the specefic String class for your specefic purpose for the above case you need the following import
                        import java.lang.String;
                        • 9. Re: reply
                          843785
                          BigDaddyLoveHandles wrote:
                          At night, elves download pr0n onto my machine. Maybe you have Nerd Elves.
                          I have those horny elves also, really sucks because I use firefox and of course firefox always brings up the last sight visited when you bring it back up. I tried to explain it was those dang elves to my poor wife who for some reason decided to use my computer and bring up firefox.

                          She didn't buy it.

                          My poor son had to take the heat for those rascally elves, he's gonna be 2 in a month and my wife already thinks he's a perv.

                          Oh well.

                          JSG
                          • 10. Re: reply
                            843785
                            BigDaddyLoveHandles wrote:
                            At night, elves download pr0n onto my machine. Maybe you have Nerd Elves.
                            Are you a Malkavian, you know those, they have invented Nerd Elves? :P
                            • 11. Re: reply
                              843785
                              Praveen_Forum wrote:
                              If you have String,String12.... as seperate classes for different purpose which is not good practise you have to import the specefic String class for your specefic purpose for the above case you need the following import
                              import java.lang.String;
                              But what generates those classes? Are they automatically generated by Java?
                              • 12. Re: reply
                                796447
                                Martin.Berger wrote:
                                Praveen_Forum wrote:
                                If you have String,String12.... as seperate classes for different purpose which is not good practise you have to import the specefic String class for your specefic purpose for the above case you need the following import
                                import java.lang.String;
                                But what generates those classes? Are they automatically generated by Java?
                                You generated them. Or else some pesky elves did as was suggested.
                                • 13. Re: reply
                                  843785
                                  It think there will be no more useful replies. So i'll award those dukes now and consider this closed.
                                  See you guys, nice talking to you about nerd elves which are malkavians and download pr0n at night :P