-1

我为一个游戏做了三个活动:

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

无法调用 datahelper databaseActivity,正在获取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
4

2 回答 2

2

将此添加到您的清单文件中

<activity
        android:name="databaseActivity"
        android:label="@string/title" >
于 2013-01-25T07:43:19.220 回答
1

我认为这是问题所在。在调用DatabaseHelper类时,将当前的实例传递Activity给它,如下所示:

 DataBaseHelper myDbHelper = new DataBaseHelper(this); //Here this is the instance of the current activity
于 2013-01-25T07:27:23.090 回答