• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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
 
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.
 
Marshal
Posts: 60136
188
  • 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
 
Sheriff
Posts: 21459
96
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: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!