wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes not dereferenced error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "not dereferenced error" Watch "not dereferenced error" New topic
Author

not dereferenced error

marc spoon
Greenhorn

Joined: Aug 08, 2001
Posts: 13
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
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
thanks Colin!
will try that
marc spoon
Greenhorn

Joined: Aug 08, 2001
Posts: 13
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
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);
}
}

 
Don't get me started about those stupid light bulbs.
 
subject: not dereferenced error