Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Annonynous inner class error

 
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends! Im testing annonymous classes and I cant get it compiled. See my test:

When I try to compile this code the java says that I need to put a ';' to close the block. Whats wrong?
Im getting this error "No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test)."
Can someone explain what the compiler is talking about?
Thanks!
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 25, and you have another error ...

WP
 
Vinicius Souza
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William P O'Sullivan wrote:Line 25, and you have another error ...

WP


I putted the ";" and fixed the code but now Im get a new (and more confusing) error....
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me guess, something along the lines of "return type"?

EDIT: I see you already got that one.
How about letting us know what error you are getting?

WP
 
Vinicius Souza
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William P O'Sullivan wrote:Let me guess, something along the lines of "return type"?

WP


Im getting this error :

Someone can explain it to me? Thanks!
 
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not have New Xuxu ( a non-staitic variable) in a static context (the main method)
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XuXu class is a non-static member of the Test class, which means you must have an instance of Test to have an instance of XuXu. So you might change the main method to something like this:


Or you could make XuXu static...
 
Vinicius Souza
Ranch Hand
Posts: 86
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Humm, its make sense guys. Thanks a lot for yours explanations.
 
Hey! You're stepping on my hand! Help me tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic