Hi all, first post here.
I've been having this problem and suddenly thought "Is this the equivalent of trying to fix my car trouble by experimenting with different types of gas, when the real problem is I've put the wheels on the roof...?". In other words, I'm wondering if my program design is just plain wrong. I've done some OOP in C++ before, but Java is not C++ I'm beginning to notice. So here's what I've done:
I made a pretty schoolbook type class by the name Terms, with three private data members 'term', 'category' and 'definition', all of data type String. I made three public get methods, each of which returns the value of one of the data mambers. I made a public set method that receives three strings as arguments and assigns these to the three data members. Finally, I've made a public constructor which calls the set method and passes three empty strings as arguments. So far, so good.
To test the use of this class, I've then made a simple console application where in PSVM (public static void main) I create single instances of the objects and use all the methods. That works fine.
The problem begins when I create an array of the data type Terms (the name of the class I created before). In PSVM, I try to run a small for-loop to fill the array with a few terms, and then another for-loop to display the contents just using the get methods of the class Terms. I get an error message of the type "non-static method cannot be called from static method main" (cannot remember the exact wording - I'm sitting at work now and don't have the message in front of me, sorry). Okay, so I try to move these operations to separate methods called fillArray() and displayArray(), but these methods cannot be called from static method main either.
So, is my design fundamentally flawed? I am trying to force my car to drive upside-down so to speak? Although it might be possible to make that run somehow, I'd rather learn proper design, the way Java is intended to work...
(If it doesn't sound like an obvious problem with the design, I guess it's a syntax error in the code, and I'll have to supply it when I get home later today.)
Grateful for all suggestions!
Flo
I've been having this problem and suddenly thought "Is this the equivalent of trying to fix my car trouble by experimenting with different types of gas, when the real problem is I've put the wheels on the roof...?". In other words, I'm wondering if my program design is just plain wrong. I've done some OOP in C++ before, but Java is not C++ I'm beginning to notice. So here's what I've done:
I made a pretty schoolbook type class by the name Terms, with three private data members 'term', 'category' and 'definition', all of data type String. I made three public get methods, each of which returns the value of one of the data mambers. I made a public set method that receives three strings as arguments and assigns these to the three data members. Finally, I've made a public constructor which calls the set method and passes three empty strings as arguments. So far, so good.
To test the use of this class, I've then made a simple console application where in PSVM (public static void main) I create single instances of the objects and use all the methods. That works fine.
The problem begins when I create an array of the data type Terms (the name of the class I created before). In PSVM, I try to run a small for-loop to fill the array with a few terms, and then another for-loop to display the contents just using the get methods of the class Terms. I get an error message of the type "non-static method cannot be called from static method main" (cannot remember the exact wording - I'm sitting at work now and don't have the message in front of me, sorry). Okay, so I try to move these operations to separate methods called fillArray() and displayArray(), but these methods cannot be called from static method main either.
So, is my design fundamentally flawed? I am trying to force my car to drive upside-down so to speak? Although it might be possible to make that run somehow, I'd rather learn proper design, the way Java is intended to work...
(If it doesn't sound like an obvious problem with the design, I guess it's a syntax error in the code, and I'll have to supply it when I get home later today.)
Grateful for all suggestions!
Flo