1

我试图让画布在固定的时间内绘制一些图片。就像屏幕上显示的一个项目,它在 5 秒后消失。然后再过 3 秒后,会抽取一个新项目并持续 5 秒。我使用 Timer 和 TimerTask 如下

    public class PowerUpMaking extends TimerTask{
        public void run() {
              test = 1;
              powerUp = new Powerup(players.get("player1"),getHeight());                
        }
    }

我在构造函数中声明了 powerUp。整个事情都在一个扩展 View 的类中。我想做的只是为引用变量创建一个新对象。事实证明第一行是有效的,但第二行不是通过检查日志。我应该如何处理这种情况?如果有人可以提供帮助,非常感谢。第一次在这里提问。

4

1 回答 1

0

Not specifically sure what your error is: you should paste the logs so we can better determine what's going on.

If you're creating objects within a nested class you have to make sure that everything needed to create the object is available: is players an instance variable? Is it null when you are trying to create the object? Are you getting a NullPointerException from players.get or from getHeight()? Without the error logs it is very difficult to get the right answer.

于 2012-05-07T15:39:57.570 回答