Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double cannot be dereferenced

 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12124
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. I'm glad the fog is clearing!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic