• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"Non-static method cannot be referenced from a static context" ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I take it you're fairly new to Java (as I am) so I don't want you to get ahead of what you are learning but this looks like a good problem for the "Collections" interfaces.
try reading
http://java.sun.com/docs/books/tutorial/collections/interfaces/index.html
Good Luck,
Gary.
 
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..

Maybe this is what youare doing??
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change to public void main(String []args)

insted..... it should run.... Dynamic non static methords can not be static...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by I Dispise:
change to public void main(String []args)

insted..... it should run.... Dynamic non static methords can not be static...


Java requires that main() be declared static, so this is not an option. I think other people have given the correct answer, though.

Layne
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

hope will help.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic