本文介绍了int无法解除引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从java开始(我正在学习microedition)并且我得到了这个错误:int无法解除引用在下面的类中:
I am beginning in java (I'm learning in microedition) and I got this error: "int cannot be dereferenced" in the following class:
class DCanvas extends Canvas{
public DCanvas(){
}
public void drawString(String str, int x, int y, int r, int g, int b){
g.setColor(r, g, b); //The error is here
g.drawString(str, x, y, 0); //and here
}
public void paint(Graphics g){
g.setColor(100, 100, 220);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
我在这里做错了什么?
我来自PHP和ECMAScripts,我能够以这种方式传递我的函数参数,所以我真的不明白这个错误。
What am I doing wrong here?Well I came from PHP and ECMAScripts where I was able to pass my function arguments this way so I really don't understand this error.
推荐答案
g
drawString
是您传入的颜色值,而不是您的图形
参考。因此,错误是当您尝试在 int
上调用方法时,您无法做到这一点。
The g
in drawString
is the color value you've passed in, not your Graphics
reference. So the error is when you're trying to call a method on an int
, which you can't do.
// Passing an integer 'g' into the function here |
// V
public void drawString(String str, int x, int y, int r, int g, int b){
// | This 'g' is the integer you passed in
// V
g.setColor(r, g, b);
g.drawString(str, x, y, 0);
}
这篇关于int无法解除引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!