致命异常:UpdateThread,空指针异常

时间:2013-01-25 07:23:08

标签: java android eclipse sqlite andengine

我为游戏制作了三项活动:

1. gameActivity - 从databaseActivity调用方法来更新分数 2. databaseActivity ---从dataHelperActivity调用更新方法 3。dataHelperActivity ---有更新方法

  

无法在databaseActivity中调用datahelper,获取NullPointerException

01-25 12:22:38.352: E/AndroidRuntime(2869): FATAL EXCEPTION: UpdateThread
01-25 12:22:38.352: E/AndroidRuntime(2869): java.lang.NullPointerException
01-25 12:22:38.352: E/AndroidRuntime(2869):     at com.snakegame.database.SnakeDatabase.manipulateCurrency(SnakeDatabase.java:1597)
01-25 12:22:38.352: E/AndroidRuntime(2869):     at com.snakegame.classic_mode.SnakeGameWithLevelActivity$16.run(SnakeGameWithLevelActivity.java:1779)
01-25 12:22:38.352: E/AndroidRuntime(2869):     at org.andengine.engine.handler.runnable.RunnableHandler.onUpdate(RunnableHandler.java:42)
 01-25 12:22:38.352: E/AndroidRuntime(2869):    at org.andengine.engine.Engine.onUpdateUpdateHandlers(Engine.java:596)
 01-25 12:22:38.352: E/AndroidRuntime(2869):    at org.andengine.engine.Engine.onUpdate(Engine.java:585)
 01-25 12:22:38.352: E/AndroidRuntime(2869):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
01-25 12:22:38.352: E/AndroidRuntime(2869):     at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)
01-25 12:22:38.398: D/AndEngine(2869): SnakeGameWithLevelActivity.onPause @(Thread: 'main')
01-25 12:27:38.398: I/Process(2869): Sending signal. PID: 2869 SIG: 9

2 个答案:

答案 0 :(得分:2)

在清单文件中添加

<activity
        android:name="databaseActivity"
        android:label="@string/title" >

答案 1 :(得分:1)

我认为这是问题所在。在您致电DatabaseHelper课程时,请将当前Activity的实例传递给该课程,如下所示:

 DataBaseHelper myDbHelper = new DataBaseHelper(this); //Here this is the instance of the current activity