• Post Reply Bookmark Topic Watch Topic
  • New Topic

Non-static variable this cannot be referenced from a static context - error  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call an actionListener which is shown below in my PSVM :


I get the following error :

Frame.java:409: error: non-static variable this cannot be referenced from a static context
menuItem1.addActionListener(new testMenuItemListener());
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mistake is actually having too much in a static context. Have a look at our FAQ about the main method.

And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!