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

getting string

arjan pronk
Greenhorn

Joined: May 21, 2008
Posts: 9
Hey guys,

I've ran into a point where I can't seem to get it work correctly and was hoping you guys could point me in the right direction.

I want to get the String delay from the run() function. I've declared it in the checklocation class earlier but then it won't get changed.




[ June 01, 2008: Message edited by: arjan pronk ]
[ June 01, 2008: Message edited by: arjan pronk ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
More of a beginner's question.

You are passing an argument to the badly-named ld method and it is local to that method and is not in scope when you reach the other method.
You are then declaring a String with the same name in the run method, which shadows the field, so no changes are applied to the field. If you want to apply those changes to the field, remove the declaration of "delay" from the run() method.
arjan pronk
Greenhorn

Joined: May 21, 2008
Posts: 9
This was how my code was first





this works fine in this class but the problem is I need to get past another class,



[ June 01, 2008: Message edited by: arjan pronk ]
[ June 01, 2008: Message edited by: arjan pronk ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
The problem with the ld method is that you insist on returning its parameter. Suggest deleting the return statement, and changing the return type to void.
arjan pronk
Greenhorn

Joined: May 21, 2008
Posts: 9
But if I don't return the String delay then I won't be able to use the string in that 2nd class.

think of it like this


outer
----
inner
----
function
----
delay
----
----
---- So I need to get it up 2 classes
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
Originally posted by arjan pronk:
But if I don't return the String delay then I won't be able to use the string in that 2nd class.
No such thing as a function in Java, only methods.

All you achieve with returning a String from the present form of the delay(String) method is sending the String back where it came from. You are not assigning a field, nor are you sending the String anywhere else. I still think you ought to have a void return type for that method. It might be more appopriate to ahve a setDestination() method and keep the String as a field. BTW: Delay doesn't seem to me to be a good name from the String.
arjan pronk
Greenhorn

Joined: May 21, 2008
Posts: 9
In the end, I had to make delay static for it to work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting string
 
Similar Threads
Thread not starting
Threads: sleep() !
either a pim error or a stupid mistake
Accessing private variable
security.exception