• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

not dereferenced error  RSS feed

 
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
 
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);
 
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);
}
}

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!