Results 1 to 6 of 6
  1. #1
    yvijai is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Pls solve my "Cannot find symbol" error

    import java.awt.Canvas;
    import java.awt.Graphics;
    import java.awt.FontMetrics;
    import java.awt.Rectangle;

    public class TextTwo extends Canvas {
    TextTwo() {
    setSize(200,200);
    }
    public void paint(Graphics g) {
    Rectangle rect;
    rect = getBounds();
    String str;
    str = "I'm in the center!";
    FontMetrics fm = g.getFontMetrics();
    int strwidth ; fm.StringWidth(str);
    int y = rect.height / 2;
    int x = (rect.width / 2) - (strwidth / 2);
    g.drawString(str,x,y);
    }
    }

    There is a problem showing in this line """ int strwidth ; fm.StringWidth(str); """"

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default Re: Pls solve my "Cannot find symbol" error

    the error is "The method StringWidth(String) is undefined for the type FontMetrics" and the quick fix is "change to stringWidth(..)"

    and i suppose the line with int strwidth; should be:int strwidth = fm.stringWidth(str);

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Pls solve my "Cannot find symbol" error

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    yvijai is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: Pls solve my "Cannot find symbol" error

    The actual problem is when i type javac *.java for compilation it is showing as cannot find symbol in command prompt

  5. #5
    yvijai is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: Pls solve my "Cannot find symbol" error

    I am unable to find out that which symbol has to be inserted in between the below line

    int strwidth ; fm.StringWidth(str);



    i.e. between intstrwidth and fm.StringWidth(str)

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default Re: Pls solve my "Cannot find symbol" error

    you declare a variable strwidth of type int but you never initialize this variable. this will produce an error saying: "TextTwo.java:18: error: variable strwidth might not have been initialized"

Similar Threads

  1. Strange "Cannot find symbol" error...
    By JimmyD in forum New To Java
    Replies: 8
    Last Post: 04-19-2012, 09:39 PM
  2. Strange "Cannot find symbol" error...
    By JimmyD in forum Advanced Java
    Replies: 7
    Last Post: 04-19-2012, 09:37 PM
  3. "Cannot find symbol" error
    By MBD in forum New To Java
    Replies: 5
    Last Post: 09-27-2011, 02:41 PM
  4. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 09:51 PM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM

Posting Permissions

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