0

Possible Duplicate:
Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”'

i got this error after i added a method called setConstraints in Generator.class.im free from error when i compiled. this is the error: Exception in thread "main" java.lang.NoSuchMethodError: rtg.Generator.setConstra ints(Ljava/util/ArrayList;)V at rtg.DefaultPrompt.main(DefaultPrompt.java:117)

this is the method of setCostraints() in Generator.java

private ArrayList<String> constraints_list = new ArrayList<String>();
private boolean constr = false;
public void setConstraints(ArrayList<String> c)
    {
        constraints_list = c;
        constr = true;
    }

this the class that is using Generator.class

public class DefaultPrompt
{
  public static void main()
  {   
      Generator gen = new Generator();
      gen.setConstraints(constraints_list);
  }
{

both classes r in the same package.before added setConstraints, no error.

anyone knows how/why its happen?

Community
  • 1
  • 1
Roubie
  • 289
  • 1
  • 6
  • 15
  • 2
    In second code sniplet where does **constraints_list** list comes from? – Ankit May 11 '11 at 02:36
  • You error message has a space in setConstraints – Zero May 11 '11 at 02:37
  • Are you sure you haven't imported the wrong "Generator" class in your DefaultPrompt? – Kal May 11 '11 at 03:15
  • your `contraints_list` variable is outside of scope – Trevor Arjeski May 11 '11 at 03:25
  • Kal, there is no other Generator.class in rtg folder – Roubie May 11 '11 at 04:20
  • Ankit- i forgot constraint_list in 2nd code.its available outside main method.Vasu-there is no space.just copied from prompt and paste here. Kal-there is no other Generator class in rtg package – Roubie May 11 '11 at 04:24
  • This Community Wiki question lists the possible causes of this common problem: http://stackoverflow.com/questions/5407250/causes-of-java-lang-nosuchmethoderror-main-exception-in-thread-main – Stephen C Jun 28 '11 at 14:38

2 Answers2

1

Sounds like the class was not re-compiled after you added the method. Sometimes this happens in some environments. Try deleting all the .class files in the directory and re-compiling again.

Vincent Ramdhanie
  • 98,815
  • 22
  • 134
  • 183
  • yes,thanks a lot.its works.i deleted all class file and re compile everything.its done..good job Vincent – Roubie May 11 '11 at 04:29
-1

did u noticed the error clearly u can see the space in the method name

Exception in thread "main" java.lang.NoSuchMethodError: rtg.Generator.setConstra ints(Ljava/util/ArrayList;)V at rtg.DefaultPrompt.main(DefaultPrompt.java:117)

developer
  • 9,003
  • 29
  • 80
  • 144
  • 2
    i copied from prompt and paste here without edit it.there is no space between setConstra and ints.in fact, if this happen,i straightly get the error when i compile – Roubie May 11 '11 at 04:18