• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char cannot be dereferenced

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,The below is a part of a code in my program to split a sentence to a particular part(ie).
"sip show peers" displays the output like this:

Name/username Host Dyn Nat ACL Port Status
5102/5102 (Unspecified) D 0 Unmonitored

Here i need to take the Name/username separately.for that i have tried the following code.


This displays the following error.

HelloLive.java:209: char cannot be dereferenced
if(a.equals(" "))

i have tried single quotes instead of double quotes too.but same error.Anyone help me please.

Thanks.
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The type char is a primitive -- not an object -- so it cannot be de-referenced.

Maybe, you need to use the wrapper type: Character.

Kaydell
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe, but in the particular statement in question, the easiest fix is to use



Note that, because a is a primitive char, not a String, it is OK to use == for equality testing. Remember that it is usually wrong to use == for equality testing of a String.
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

On the same topic, i tried the code below, and it worked fine.





prints out ===> f :: d

}

returns ====> false



 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method appears to trying to find whether f and d are the same, and they aren't.
Worthwhile reading the API: in particular read the compareTo() method and also the java.lang.Comparable<T> interface.
 
Shaddy Krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can anybody help me? i have this piece of code and i get the error char cannot be dereferenced... im new at this..
this piece of code is in a method..and i have to count the total consonants in a word.. im trying to compare it to a string array of vowels.

for (int outerCounter = (wordLength - 1); outerCounter >= 0; outerCounter --)
{
for (int innerCounter = 1; innerCounter <= MAX; innerCounter ++)
{
if ((word.charAt(outerCounter)).equalsIgnoreCase(vowels[innerCounter]))
{
totalConsonants ++;
}
}
}
return totalConsonants;
 
Henry Wong
author
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shaddy Krishnan wrote:Hi can anybody help me? i have this piece of code and i get the error char cannot be dereferenced... im new at this..



Considering that you posted onto this topic, we'll assume that you read the answers in this topic.... so... can you elaborate what you don't understand about the answers? Otherwise, we'll just be giving you the same answer that was already provided.

Henry
 
Shaddy Krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah lol i get it now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic