• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

"char cannot be dereferenced error"

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Robbie Harjes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now you have too many parens in the "compareTo". You are saying "compareTo((something))". One layer too many parens.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I don't find "replace". Maybe you are thinking of the String class?
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic