Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Beginning Java and the fly likes can't be dereferenced... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

can't be dereferenced...

Robbie Harjes

Joined: Nov 09, 2003
Posts: 22

This is obviously inside a for loop, i++ until there's no more characters left to process. For some reason I'm getting the "char cannot be dereferenced" error. I don't know how to fix this seeing how I'm using a .replace() function.. Not like I can just go something like "TEMP = Character.toUpperCase(TEMP);"
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

The class "char" has a "replace" method?
So if you are in a loop the first interation would set TEMP to "h". And you want to than replace "h" with the result of a call to "replace" on the same variable. If there is a "replace" method, than why would you need to do the assignment?

Please ignore post, I have no idea what I am talking about.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31668

TEMP is called a primitive variable. Primative types include char, int and boolean. These types cannot be used to call methods. This is why you are getting the de-reference error.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Robbie Harjes

Joined: Nov 09, 2003
Posts: 22
Thanks for all the help. I'm too stupid to realize the obvious. Thanks again.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
Please add further responses to this duplicate thread.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: can't be dereferenced...