Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Error : "char cannot be dereferenced"

  Asked By: Kiswar    Date: Jun 27    Category: Java    Views: 1894
  

im running this code and im having trouble understanding the
error the complier is giving me ...........can u please tell me how
to fix it?

for (int i=0; i<word.length(); i++) {
Node node = new Node();
char alpha = word.charAt(i);
*** int index = alpha.getNumericValue(); ***
branch[index - 97] = node;
Node[] branch2 = new Node[27] ;
node.next = branch2;

for the line in between the stars i get the Error Messege:

"char cannot be dereferenced"

can u please tell me what to do ?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Dennis Hayes     Answered On: Jun 27

The problem is that "char" is not a class, is a
primitive type, so you can't call methods on a
"char" variable, if you want to convert a char
into an int, you can do this casting:

int index  = (int) alpha;

 
Answer #2    Answered By: Canan Kaya     Answered On: Jun 27

if have called import java.lang.* at the begining then try
int index=Character.getnumericvalue(alpha); I hope this will solve yr
problem...PLz do let me know if it works as I am also in the process of
learning and hopefully this will help me as well..

 
Answer #3    Answered By: Steve Boyd     Answered On: Jun 27

well I amnot an experienced java programmer but hopefully this solution will
solve yr problem.
If u have included java.lang library at the begining. then replace yr code
in stars! with
int index  = character.getnumericvalue(alpha); I hope this will work..plz do
let me know as it will be helpful for me as well..

 
Answer #4    Answered By: Raul Clark     Answered On: Jun 27

the type char  has no functions, as it's a fundamental data type. What
you want to do is use wrapper class's function
Character.getNumericValue(alpha)

 
Answer #5    Answered By: Nixie Schmidt     Answered On: Jun 27

getNumericValue() is a method of the Character object, not the char  primitive.
Primitives have no methods. So your code  should be

int index  = Character.getNumericValue(alpha);

untested, but should work.

 
Didn't find what you were looking for? Find more on Error : "char cannot be dereferenced" Or get search suggestion and latest updates.




Tagged: