Android Emulator is Force Closing
My Android Emulator is force quitting my program every time I try to run it. I have no idea why, please help me!
public class AsteroidsToo extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AsteroidWorld(3).bigBang(this);
}
}
Here is the LogCat errors:
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开发者_StackOverflow中文版 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}
Here is the Code for my constructor:
/**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;
I also get an error saying:
[2011-07-02 20:08:08 - Emulator] 2011-07-02 20:08:08.156 emulator[14734:903] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz
Here is my ship constructor
/**Represents the Ship in the game*/
class Ship extends FloatObject{
Image SpaceShip = new FromFile("spaceship.png");
double angle;
double speed = 2;
My guess is that, in the Ship's constructor, which you are not showing, the line in that where you create a new instance of FromFile, you are passing a null value to the FromFile's constructor. FromFile's constructor expects a String. You might even be attempting to pass a String to it, but whatever it is getting there is probably actually null.
FromFile's constructor is putting a value into a HashTable, and that value is null instead of what it is expecting. That's all I can gather from not being able to see everything necessary here.
精彩评论