Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not dereferenced error

 
marc spoon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Colin!
will try that
 
marc spoon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic