Can someone tell me why the following code doesn't work?
The compiler gives me the following error:
"test.java"":Error #:300: method isLetter(char) not found...
Many other simple programs like this work so I know the IDE is working
(JBuilder 3.5).
import java.lang.Character; // java.lang automatically included, but I need
it to work!
public class test {
public static void main(String args[]) {
char x;
x = 'x';
if (isLetter(x)) // not acceptable?
System.out.println("Is letter");
}
}
Any help appreciated,
Chris
isLetter() is a static method in class Character. Use :-
if (Character.isLetter (cMyChar)) ...
instead.
steve
Sent via Deja.com http://www.deja.com/
Before you buy.
Don't do it that way, do it this way:
public class test {
public static void main(String args[]) {
char x;
x = 'x';
if (Character.isLetter(x)) // not acceptable?
System.out.println("Is letter");
}
}
The import is *not* needed, because as you say, java.lang.* is imported
by default.
The error was telling you that no method named 'isLetter' existed in
your class 'test'.
jim
------------------------------------------------------------
James P. White Netscape DevEdge Champion for IFC
IFC Exchange - Insanely great Java - http://www.ifcx.org
> Hello,
>
> Can someone tell me why the following code doesn't work?
>
> The compiler gives me the following error:
> "test.java"":Error #:300: method isLetter(char) not found...
>
> Many other simple programs like this work so I know the IDE is working
> (JBuilder 3.5).
>
> import java.lang.Character; // java.lang automatically included, but I need
> it to work!
> public class test {
> public static void main(String args[]) {
> char x;
> x = 'x';
> if (isLetter(x)) // not acceptable?
> System.out.println("Is letter");
> }
> }
>
> Any help appreciated,
> Chris
"import java.lang.Character" doesn't mean, that you can
reference the fields of `Character´ without the leading
class reference. It only implies that you can
write`"Character" instead of "java.lang.Character". But
in the case of the "java.lang" package, this doesn't
change anything because there is an implicit "import
java.lang.*" in every source file
Bye