wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""char cannot be dereferenced error"" Watch ""char cannot be dereferenced error"" New topic
Author

"char cannot be dereferenced error"

Robbie Harjes
Greenhorn

Joined: Nov 09, 2003
Posts: 22
I'm trying to make a simple, 1-to-1 character conversion "Encryption" program. Here is the code:

(The program is not finished...Just what I have)
I know it has to do with the array referencing... I read somewhere to try putting it in an extra set of parathesee's, but that didn't work.. Sorry if this paintstakingly obvious... I can't figure it out.
[ November 09, 2003: Message edited by: Robbie Harjes ]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

You didn't mention what your exact problem is. Does it not compile? What is the error?
I think you have an extra comma after last set - mapping z to a.
And this

I think you are doing the "==" at the wrong level. You want to compare the result of the "compareTo" to zero. At the moment you are comparing the character at [1][i] to zero.


Please ignore post, I have no idea what I am talking about.
Robbie Harjes
Greenhorn

Joined: Nov 09, 2003
Posts: 22
The exact problem is this: It won't compile. When I try to compile it, I get the "char cannot be dereferenced" error, and it points to the periods:
if (TEMP.compareTo((ct[1][i])==0)) {
^
*and*
TEMP=TEMP.replace((ct[1][i]), (ct[2][i]));
^
William Barnes... I believe you have it right... But how would I fix that? create a new char (ex. char NEW=ct[1][i] so that I am comparing the character and not the reference to the array?
Robbie Harjes
Greenhorn

Joined: Nov 09, 2003
Posts: 22
Sorry about the double posting here...
Your right on that it should be: if (TEMP.compareTo((ct[1][i]))==0)
but I still get the errors:
<pre>
C:\java>javac mono.java
mono.java:46: char cannot be dereferenced
if (TEMP.compareTo((ct[1][i]))==0) {
^
mono.java:47: char cannot be dereferenced
TEMP=TEMP.replace((ct[1][i]), (ct[2][i]));
^
2 errors
</pre>
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Now you have too many parens in the "compareTo". You are saying "compareTo((something))". One layer too many parens.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Looking at the API I see that you are using "compareTo" method incorrectly. The signiture is "int compareTo( Character, anotherCharator)". So your "TEMP" should be the first parameter in this call. Make sense?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

And I don't find "replace". Maybe you are thinking of the String class?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Ignore may answers, Jeanne Boyarsky on the other thread has it. "char" is a primative - isn't a class and doesn't have access to all those nice methods.
You can use the "Character" class instead of "char" if you want those methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "char cannot be dereferenced error"
 
Similar Threads
toUpper, toLower for chars
extracting image binary data from file
Math.Random() query
HELP~~
Dsplaying the alphabet with a loop?