aspose file tools*
The moose likes Java in General and the fly likes char cannot be dereferenced 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 » Java in General
Bookmark "char cannot be dereferenced" Watch "char cannot be dereferenced" New topic
Author

char cannot be dereferenced

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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

Joined: Nov 18, 2006
Posts: 689

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

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
Hello,

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





prints out ===> f :: d

}

returns ====> false



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
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

Joined: Dec 05, 2009
Posts: 2
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Shaddy Krishnan
Greenhorn

Joined: Dec 05, 2009
Posts: 2
yeah lol i get it now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: char cannot be dereferenced