Anonymous Human
Anonymous Human

Reputation: 1948

isNumber() on Integer throws error

Does this error mean I am calling isNumber() on a null value? I can't seem to understand it.

No signature of method: 
java.lang.Integer.isNumber() is applicable for argument types: () values: []. 

Stacktrace follows:
Message: No signature of method: 
java.lang.Integer.isNumber() is applicable for argument types: () values: []

Upvotes: 1

Views: 6881

Answers (2)

Victor
Victor

Reputation: 5121

This error mean: the class java.lang.Integer has no method isNumber()
The method isNumber() belongs to class java.lang.String. See the docs: http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#isNumber()

Maybe you are trying to do something like this:

123.isNumber() // will trow the error

while the correct is:

"123".isNumber()

Upvotes: 8

Jeff Storey
Jeff Storey

Reputation: 57192

isNumber is a method of String. You're calling it on an integer - http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#isNumber()

It wouldn't make sense to call isNumber on a number. You know it is already. You would want to call it on the string that might be represnting a number.

Here's how to reproduce in the groovy shell.

groovy:000> new Integer(5).isNumber()
ERROR groovy.lang.MissingMethodException:
No signature of method: java.lang.Integer.isNumber() is applicable for argument types: () values: []

Upvotes: 2

Related Questions