aspose file tools*
The moose likes Beginning Java and the fly likes non-static variable this cannot be referenced from a static context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "non-static variable this cannot be referenced from a static context" Watch "non-static variable this cannot be referenced from a static context" New topic
Author

non-static variable this cannot be referenced from a static context

Ashish Maharaja Singh
Greenhorn

Joined: Jun 06, 2011
Posts: 8
please tell me the error in my concepts. I am get this error on line "TempArray ta = new TempArray(le,ri);"



Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Hi Ashish,

Welcome to JavaRanch
Please use code tags while posting question it simple just select your code and click on Code tag in the window where you are writing Question

SCJP6.0,My blog Ranchers from Delhi
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The problem is that TempArray is an inner class of Test. Therefore you need an instance of Test to create an instance of TempArray.
You can make TempArray a not-inner class or use an instance of Test to create a TestArray: new Test().new TestArray();


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And welcome to the JavaRanch.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

And of course posting the error message would help.

My guess is that since TempArray is not declared as static the compiler is complaining that you are trying to access it in a static context.

Edit: :-) I'm so slow!


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Ashish Maharaja Singh
Greenhorn

Joined: Jun 06, 2011
Posts: 8
thanks ! that was a bad error on my part.
Prasanna Kumaar
Ranch Hand

Joined: Feb 08, 2011
Posts: 30
Ashish Maharaja Singh wrote:please tell me the error in my concepts. I am get this error on line "TempArray ta = new TempArray(le,ri);"







i think its because you did not declare size and TempArray variables..and another fault i see is class TempArray does not have a method named "Show"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: non-static variable this cannot be referenced from a static context