Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Beginner Help with Static and Non Static 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 "Beginner Help with Static and Non Static" Watch "Beginner Help with Static and Non Static" New topic
Author

Beginner Help with Static and Non Static

Tom Carr
Greenhorn

Joined: Oct 02, 2012
Posts: 2
Hi There,

I am a beginner to java but I have written some basic C# before. But i have never really grasped the OOP concept.
I am starting a project recode for a program i wrote in C# with a better GUI.

Basically in this code I am trying to create a instance of a "LoadIni" class and then get/set the data in it while running its procedures to write to the ini and read from the ini.

Here is my first class EOMWindow:


This is my second class which is called IniControl





The issue i am having is i can't use the line

as it gives the error : non-static varible csvExportDirectoryText cannot be referenced from a static content.
Also i am unable to use the instance "ini" in my button actions (closeButtonActionPreformed) obviously because the IniControl is created within the Run function. How do i place the LoadIni instance so i can access it in the entire EOMWindow class ?

Thanks you very much for reading and any help would be gratefully appreciated .
Tom
Tom Carr
Greenhorn

Joined: Oct 02, 2012
Posts: 2
Just an update.
I have realised that the error didn't relate to the "ini.ReturnAuditDir" but actually to the csvExportDirectoryText.setText being set from within that void.

But i still have an issue on accessing the "ini" instance in the rest of the class.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
You can tell people who come from C#; they go straight for an IDE. And they get code with the IDE’s personality stamped all over it
C# is an OO language, too. How have you managed to write C# without learning object‑orientation?
The ini variable appears to be a local variable in the overridden run() method. When you get to the end of the method, it goes out of scope. You might need an Application class, which has a Wini object as a field. Initialise the field from the Application constructor. That is the sort of thing which is difficult to do from underneath a GUI. You would probably do better to remove the GUI for the time being, and set up the application like a ConsoleApplication. Once you have it running nicely at the command line, then you can replace the GUI on top of it. Obviously you can record your GUI code somewhere to make it easier to reconstruct.

And welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
 
subject: Beginner Help with Static and Non Static
 
Similar Threads
show image on button click
Dynamic textfield creation
Unknown column 'mkl' in 'field list
Threading basics problem
My program forgets about previously stored elements