Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The method add(Component) in the type Container is not applicable for the arguments (Class)Why?  RSS feed

 
pietro quarta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all, this is the code....I use eclipse that has warned me of this error:The method add(Component) in the type Container is not applicable for the arguments
(Class) at the line 09 of Main.java
What i can do to fix it?
Main.java

Class.java

Bye
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Class is not a Component. Also maybe you should avoid using the classname Class because there is already a Class class in Java.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Javaranch.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
Change the name of your class to . . . and you will probably need to rename the file that class is in to MyComponent.java
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pietro quarta wrote:

You should add "super.paintComponent(g);" between those two lines.
 
pietro quarta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you a lot. This forum is perfect for me that i'm new in the world of the java.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Branden Dernell
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had this same exact error in my code when my IDE actually should have not been throwing the error at all to begin with. When I was using Eclipse, I got rid of this error by closing and moving any other projects that I had open currently. Since my other project that was open was dealing with very similar code to my New Project I just recently made, I think my IDE was confused. So I closed the other project I had open already, copied all my code in the java class file with the error, then deleted that java class file with the error, then remade a new java class file with the same name, and pasted the code back in and then my error was gone.

My other project = code was working
New Project = Same exact code as other project, but wasnt working...

Good luck and hope this helps any.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!