This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ashish Maharaja Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the JavaRanch.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ashish Maharaja Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ! that was a bad error on my part.
 
Prasanna Kumaar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic