• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annonynous inner class error  RSS feed

 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • 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!
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 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: 70
1
Chrome Java Netbeans IDE
  • 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
Chrome IBM DB2 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: 70
1
Chrome Java Netbeans IDE
  • 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!
 
Larry Frissell
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)
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • 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: 70
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Humm, its make sense guys. Thanks a lot for yours explanations.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!