Results 1 to 3 of 3

Thread: Label Error

  1. #1
    harry624 is offline Member
    Join Date
    Dec 2012
    Rep Power

    Default Label Error

    Hi guys I am new to java and learning it on my own. I have written this code...

    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 acm.program.Program.runHook(
    at acm.program.Program.startRun(
    at Source)

    What am i doing wrong.

    Thanks guys for your help

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default 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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default 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

  1. How to use label in java - i got error
    By rjagan in forum New To Java
    Replies: 4
    Last Post: 04-05-2011, 02:36 PM
  2. First SWT Label
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:38 PM
  3. Example of SWT Label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 12:02 PM
  4. Using java.awt.Label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts