Results 1 to 3 of 3
Thread: Label Error
- 12-23-2012, 12:24 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
Label Error
Hi guys I am new to java and learning it on my own. I have written this code...
import acm.graphics.*;
import acm.program.*;
public class Bio extends ConsoleProgram {
public void run() {
add(new GLabel("Hello, world!"), 20, 20);
}
}
When I run the program it doesn't create the label it gives me the following error...
Exception in thread "Thread-4" java.lang.Error: Unresolved compilation problem:
The method add(Component, int) in the type Container is not applicable for the arguments (GLabel, int, int)
at Bio.run(Bio.java:15)
at acm.program.Program.runHook(Program.java:1592)
at acm.program.Program.startRun(Program.java:1581)
at acm.program.AppletStarter.run(Program.java:1939)
at java.lang.Thread.run(Unknown Source)
What am i doing wrong.
Thanks guys for your help
- 12-23-2012, 01:29 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Label Error
The error means that you've passed invalid number of arguments to the add() method. The method only accept two arguments. The first is of type Component, the second is an int. But what you did was that you've passed three arguments to the add() method.
Last edited by wsaryada; 12-23-2012 at 01:31 AM.
Website: Learn Java by Examples
-
Re: Label Error
The error is telling you exactly what's wrong -- you're trying to call a method that doesn't exist as there is no add(component...) method that takes two ints as additional parameters. You will need to check out the API for the ACM graphics library to see what methods are in fact available for you to use. Or better yet, I suggest that you avoid using the ACM library and instead use a Java standard GUI library such as Swing and learn GUI coding with that. Many more of us are familiar with Swing and you will likely get better help if you stick with this library.
Similar Threads
-
How to use label in java - i got error
By rjagan in forum New To JavaReplies: 4Last Post: 04-05-2011, 02:36 PM -
First SWT Label
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:38 PM -
Example of SWT Label
By Java Tip in forum Java TipReplies: 0Last Post: 01-09-2008, 12:02 PM -
Using java.awt.Label
By Java Tip in forum Java TipReplies: 0Last Post: 01-02-2008, 06:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks