0

I have issues with calling the java class from grails application.

Controller class:

class MyController{

    def index() { 
         somepkg.MyJavaClass.method()
    }
}

Java class:

package somepkg;

public class MyJavaClass{

    public void method() {
           // ... some logic here
    }
}

The error:

No signature of method: static somepkg.MyJavaClass.method() is applicable for argument types: () values: [] Possible solutions: wait(), any(), find(), wait(long), each(groovy.lang.Closure), find(groovy.lang.Closure)

2
  • 1
    Somehow you don't mention what the problem is so it's hard to help you. One thing is on my mind though - are you aware of the fact that object have to be created before you can call it's method? Commented Feb 11, 2014 at 12:53
  • I just forgot - but now is updated Commented Feb 11, 2014 at 12:58

1 Answer 1

1

If you want to call a method of a class without creating an instance, the method has to be marked static:

public static void afada() throws FileNotFoundException, UnsupportedEncodingException{
  PrintWriter writer = new PrintWriter("ediOrder.txt", "UTF-8");
  writer.println("a");
  writer.close();
}

or you have to create an instance first:

new examplepkg.testing().afada()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.