wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes My method doesn't seem to be able to access a field? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "My method doesn Watch "My method doesn New topic
Author

My method doesn't seem to be able to access a field?

Dick Hammer
Greenhorn

Joined: Jan 28, 2012
Posts: 18
Ok I edited this post in response to

Ralph Cook wrote:This is pretty much unintelligible.

It took me too long to make out that you have not posted all the code. Your description of what is supposed to happen and what does happen is also a bit obtuse; I could make some guesses about what you mean, but it likely wouldn't help since I can't see the code.

I suggest boiling down what you want to do to a small example -- put the variables in the scope they have to be in the real app, to ensure you can get to them from where you want to, but a couple of labels and buttons and a listener or two should be all you need. And then show us all of it -- where you modify these variables, where you attach the listeners, all of it. Often, in the process of making a small executable example of what you're trying to do, you may even discover the answer yourself.


Sorry about the confusion, I had kept some of the code collapsed for readability, but no need to have two big blocks of code, so here's the new shorter program. I don't understand why the method do_btnJbutton_mousePressed doesn't setText correctly. The variable TheFilePath should get set by the call to RandomNessGenerator(). What am I doing wrong in the code?

Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
This is pretty much unintelligible.

It took me too long to make out that you have not posted all the code. Your description of what is supposed to happen and what does happen is also a bit obtuse; I could make some guesses about what you mean, but it likely wouldn't help since I can't see the code.

I suggest boiling down what you want to do to a small example -- put the variables in the scope they have to be in the real app, to ensure you can get to them from where you want to, but a couple of labels and buttons and a listener or two should be all you need. And then show us all of it -- where you modify these variables, where you attach the listeners, all of it. Often, in the process of making a small executable example of what you're trying to do, you may even discover the answer yourself.
Dick Hammer
Greenhorn

Joined: Jan 28, 2012
Posts: 18
Ok thanks, check out the new edited code above.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Inside the method RandomNessGenerator you are declaring and initializing a new String variable, which happens to have the same name as the member variable. So, you're not setting the member variable, you're just initializing the new variable inside the method.

Remove the type name (String) in front of the variable name.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Dick Hammer wrote:Ok thanks, check out the new edited code above.
No, no, no.

Don’t edit code which has been replied to; that might make the reply look like nonsense.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My method doesn't seem to be able to access a field?
 
Similar Threads
JComponent problem ?
Display an image for a set time
chess game : moving piece
How can I change a .jpg icon image of an icon for a jLabel using Eclipse IDE?
modifying a tic tac toe game