Hi all! char c; String word = "someword"; boolean uppercase; c = word.charAt(0); uppercase = c.isUpperCase(); using this code i get an 'char cannot be dereferenced' error what am i doing wrong? marc
Colin Kenworthy
Ranch Hand
Joined: Aug 06, 2001
Posts: 88
posted
0
Marc, You normally get this error when you try and use a primitive (i.e. something that is not an object, like int, char, float) as if it were an object. Here you have called a method, isUpperCase(), on a char variable, c. Take a look at the Character class. Convert your char to a Character and then you can use this method on it. Alternatively - see if there is a method in the String class that returns you a Character instead of char.
marc spoon
Greenhorn
Joined: Aug 08, 2001
Posts: 13
posted
0
thanks Colin! will try that
marc spoon
Greenhorn
Joined: Aug 08, 2001
Posts: 13
posted
0
just to let you know it works fine with... char c; String word = "someword"; boolean uppercase; c = word.charAt(0); uppercase = Character.isUpperCase(c);
susha pillu
Greenhorn
Joined: Jul 25, 2001
Posts: 8
posted
0
Hi, The meaning of some terms is here. Reference : It is an address of some object Dereference : You are getting / setting the value of that object. Now in your case, c is a primitive type data and it is not an object on which you can invoke any method. Hence you are getting that error. The modified code is public class CharTest { public static void main(String[] args) { char c; String word = "someword"; boolean uppercase; c = word.charAt(0); uppercase = Character.isUpperCase(c); System.out.println("Upercase" + uppercase); } }