0

I start with groovy and I do not understand the issue which occurs.| My method in main method implements getWordsFromNumber(int) -> int as 120, so why it doesn't work?:)

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static MyClass.getWordsFromNumber() is applicable for argument types: (Integer) values: [120]
Possible solutions: getWordsFromNumber(int)

This is my code:

class MyClass {
    String numberString

    String setNumberToWord(int number) {
        switch (number) {
            case 0:
                numberString = "zero"
                break
            case 1:
                numberString = "jeden"
                break
            case 2:
                numberString = "dwa"
                break
            case 3:
                numberString = "trzy"
                break
            case 4:
                numberString = "cztery"
                break
            case 5:
                numberString = "pięć"
                break
            case 6:
                numberString = "sześć"
                break
            case 7:
                numberString = "siedem"
                break
            case 8:
                numberString = "osiem"
                break
            case 9:
                numberString = "dziewięć"
                break
        }
    }

    String getWordsFromNumber(int number) {
        int numDigits = String.valueOf(number).length()
        String result = ""
        for (i in numDigits) {
            setNumberToWord(number)
            result = result + "$numberString - "
        }
        result = result.substring(0, result.length() - 1);
        return result
    }

    public static void main(String[] args) {
        int yourNumber = 120
        getWordsFromNumber(yourNumber)
    }

}

The most of the post is code. In my opinion there is no need of additional information.

Chris
  • 63
  • 6
  • 1
    either make your methods `static` or create an instance in your main. Your (static) main can not call an instance method. – cfrick Oct 11 '21 at 12:01
  • Does this answer your question? [Java: How To Call Non Static Method From Main Method?](https://stackoverflow.com/questions/7379915/java-how-to-call-non-static-method-from-main-method) – cfrick Oct 11 '21 at 12:02

0 Answers0