Results 1 to 6 of 6
- 05-18-2012, 05:18 PM #1
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
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); """"
- 05-18-2012, 05:50 PM #2
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);
- 05-18-2012, 06:00 PM #3
Re: Pls solve my "Cannot find symbol" error
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 05-18-2012, 06:45 PM #4
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
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
- 05-18-2012, 06:47 PM #5
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
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)
- 05-18-2012, 11:17 PM #6
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
-
Strange "Cannot find symbol" error...
By JimmyD in forum New To JavaReplies: 8Last Post: 04-19-2012, 09:39 PM -
Strange "Cannot find symbol" error...
By JimmyD in forum Advanced JavaReplies: 7Last Post: 04-19-2012, 09:37 PM -
"Cannot find symbol" error
By MBD in forum New To JavaReplies: 5Last Post: 09-27-2011, 02:41 PM -
Error "can not find symbol variable"
By FullMetalHollow in forum New To JavaReplies: 5Last Post: 10-04-2009, 09:51 PM -
"Cannont find symbol Constructor" error
By Welsh in forum New To JavaReplies: 7Last Post: 01-25-2008, 12:12 AM
Bookmarks