"Non-static method cannot be referenced from a static context" ?
Kristian Andersson
Greenhorn
Joined: Apr 23, 2004
Posts: 7
posted
0
I got a class in which I want to call three methods. The problem is as stated in the subject of this post. I got no clue whatsoever of what I should to to make it work. Anyway, heres the code:
Would anyone please tell me what to do? And if you want to help out further, I would like some help with the method "reverseArrayOrder". The point with this one is, as the name suggests, to reverse the array order. I either need a way to copy the matrix that comes with the method-call, or I need to create an empty matrix with the same size and use this to temporarily store contents of the arrays while moving their contents around. Right? I've thought of using an ArrayList, but I can't come up with a way to make it work...
Greg T Robertson
Ranch Hand
Joined: Nov 18, 2003
Posts: 91
posted
0
You are attempting to call the eraseMatrixValues from the static method "main". If you did
Reason is that you can't call "non static" methods from a static method. As an alternative you could make the methods all static. As an aside classes are usually named with the first letter as a capital. [ May 10, 2004: Message edited by: Greg T Robertson ]
I had this problem when I was working with an object earlier. I kept on getting this error popping up when I kept on trying to write and retrieve data from the class file instead of the object I had created from the class..
On the other hand you should try to move all the code from main function into something else (for example public void run() {...}). After you've done this, rewrite the main method:
an alternate solution in respect to change all methods into static.
I somewhat disagree with Greg's code:The dual use of the identifier and_kri is correct, but confusing. I guess class names and variable names occupy different name spaces, but I would write: