Results 1 to 3 of 3

Thread: Label Error

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

    Default 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

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

    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 02:31 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    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, 03:36 PM
  2. First SWT Label
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:38 PM
  3. Example of SWT Label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 01:02 PM
  4. Using java.awt.Label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 07: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
  •