aspose file tools*
The moose likes Beginning Java and the fly likes Double cannot be dereferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Double cannot be dereferenced" Watch "Double cannot be dereferenced" New topic
Author

Double cannot be dereferenced

Tyler Tallman
Greenhorn

Joined: Oct 04, 2012
Posts: 20

Alright, so I have this method right here and I'm trying to call on it. I have an array of 37 doubles created, which is hzArray, and I want each one of those to do the method "tic". However, from what I understand, double is primitive and I can't call a method on it in this way. Is there a way to change my array of doubles locally into something that the method can call on?

Also, I have to use an array to solve this problem.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Why is your tic() method trying to call tic()? And what would you expect it to mean if you could to double.tic()? In other words, what are you trying to accomplish here?
Tyler Tallman
Greenhorn

Joined: Oct 04, 2012
Posts: 20
Jeff Verdegan wrote:Why is your tic() method trying to call tic()? And what would you expect it to mean if you could to double.tic()? In other words, what are you trying to accomplish here?

So there is something called the Karplus-Strong update, basically every time I call tic it applies this update one time. I have tic defined in another class, there are several files involved in this but basically whenver I press a key in my program (it is supposed to resemble playing a guitar) I want this tic method to be applied to whatever I call, and it does this several times until the sound fades out.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11295
    
  16

first: your subject says "Double", but your post says "double(s)". There is a difference, so which is it?

second: regardless of which you have, there is no such thing as a tic() method defined for a (D|d)ouble. You can only call a method that is defined for whatever the class is. If you want to call the tic() method, you need to call it using an object of whatever type tic() is defined in.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tyler Tallman wrote:I want this tic method to be applied to whatever I call


What's that supposed to mean? You can only call a method on the type on which it's defined, and on it's subtypes. For instance, java.util.Date has a setTime() method. If I have a Date object, pointed to by variable d, I can call d.setTime(). String does not have such a method, so if I have String variable s, I cannot call s.setTime().

So, if your tic() method is defined in class X, and you have a variable x of type X, you can call x.tic(). That will cause tic() to do whatever it's job is written to be. In your initial post, it looks like tic's job is to do something with a bunch of doubles, or to call tic() some more.

So, what is tic() supposed to actually do? Play a note? Play a bunch of notes?

And where do the doubles come in? Are they the frequencies?

If so, then tic() would look something like this:


(Note that you can simplify your code a bit by using a foreach loop.



Tyler Tallman
Greenhorn

Joined: Oct 04, 2012
Posts: 20
Ohh shoot yeah I see what you're saying now Jeff thanks for explaining it that way, I need to go about this some other way
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You're welcome. I'm glad the fog is clearing!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Double cannot be dereferenced