Android模拟器是Force Closing

时间:2011-07-02 17:44:41

标签: java android android-emulator

每次尝试运行时,我的Android模拟器都会强制退出程序。我不知道为什么,请帮助我!

public class AsteroidsToo extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     new AsteroidWorld(3).bigBang(this);
    }

}

以下是LogCat错误:

07-02 17:27:54.873: WARN/dalvikvm(332): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-02 17:27:54.893: ERROR/AndroidRuntime(332): FATAL EXCEPTION: main
07-02 17:27:54.893: ERROR/AndroidRuntime(332): java.lang.RuntimeException: Unable to start activity ComponentInfo{foo.AsteroidsToo/foo.AsteroidsToo.AsteroidsToo}: java.lang.NullPointerException
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.os.Looper.loop(Looper.java:123)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at java.lang.reflect.Method.invokeNative(Native Method)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at java.lang.reflect.Method.invoke(Method.java:521)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at dalvik.system.NativeStart.main(Native Method)
07-02 17:27:54.893: ERROR/AndroidRuntime(332): Caused by: java.lang.NullPointerException
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at java.util.Hashtable.put(Hashtable.java:369)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.image.FromFile.<init>(FromFile.java:25)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at foo.AsteroidsToo.Ship.<init>(AsteroidsToo.java:75)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at foo.AsteroidsToo.AsteroidWorld.<init>(AsteroidsToo.java:196)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at foo.AsteroidsToo.AsteroidsToo.onCreate(AsteroidsToo.java:13)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-02 17:27:54.893: ERROR/AndroidRuntime(332):     ... 11 more
07-02 17:27:54.923: WARN/ActivityManager(59):   Force finishing activity foo.AsteroidsToo/.AsteroidsToo
07-02 17:27:55.433: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45053848 foo.AsteroidsToo/.AsteroidsToo}
07-02 17:28:03.173: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44f2b9d8
07-02 17:28:06.287: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{45053848 foo.AsteroidsToo/.AsteroidsToo}

以下是我的构造函数的代码:

/**Represents the World*/
class AsteroidWorld extends VoidWorld{
    Ship sh;
    ArrayList<Bullet> b;
    ArrayList<Asteroids> a;
    int score;
    int HighScore;
    State state;
    int lives;
    double timer;

    public AsteroidWorld(int lives) {
        super();
        this.sh = new Ship(300.0,300.0,0.0,0.0,90.0);
        this.b = new ArrayList<Bullet>();
        this.a = new ArrayList<Asteroids>();
        this.score = 0;
        this.HighScore = 0;
        this.timer = 3.0;
        this.state = new Lose();
        this.lives = lives;

我也收到错误说:

  

[2011-07-02 20:08:08 - 模拟器]   2011-07-02 20:08:08.156   模拟器[14734:903]警告一次:这个   应用程序或它使用的库是   使用NSQuickDrawView,已经   弃用。应用应停止使用   QuickDraw并转移到Quartz

这是我的船舶构造函数

/**Represents the Ship in the game*/
class Ship extends FloatObject{
Image SpaceShip = new FromFile("spaceship.png");
double angle;
double speed = 2;

1 个答案:

答案 0 :(得分:0)

我的猜测是,在您未显示的Ship的构造函数中,您在创建FromFile的新实例的行中,您将空值传递给FromFile的构造函数。 FromFile的构造函数需要一个String。您甚至可能尝试将String传递给它,但无论它到底是什么,实际上可能都是null。

FromFile的构造函数将一个值放入HashTable中,该值为null而不是它所期望的值。这就是我无法在这里看到所有必要的东西。