我已经在论坛和谷歌上进行了一些关于初始化和使用静态字段的搜索。但我不能单独修复它,所以这里是简化的代码:
...
import android.graphics.Canvas;
...
public class MyActivity extends Activity{
...
public static Canvas myCanvas = new Canvas();
public static float myMaxX;
public static float myMaxY;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
...
myMaxX = myCanvas.getWidth(); // <=== Error, the app crashes right there
myMaxY = myCanvas.getHeight();
...
...
}
...
}
我错过了什么 ?