07-08 17:04:34.978: E/AndroidRuntime(322): FATAL EXCEPTION: main
07-08 17:04:34.978: E/AndroidRuntime(322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gurpswu.gurps/com.gurpswu.gurps.Home}: java.lang.NullPointerException
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.os.Looper.loop(Looper.java:123)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-08 17:04:34.978: E/AndroidRuntime(322): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 17:04:34.978: E/AndroidRuntime(322): at java.lang.reflect.Method.invoke(Method.java:507)
07-08 17:04:34.978: E/AndroidRuntime(322): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-08 17:04:34.978: E/AndroidRuntime(322): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-08 17:04:34.978: E/AndroidRuntime(322): at dalvik.system.NativeStart.main(Native Method)
07-08 17:04:34.978: E/AndroidRuntime(322): Caused by: java.lang.NullPointerException
07-08 17:04:34.978: E/AndroidRuntime(322): at com.gurpswu.gurps.Player.getIntField(Player.java:153)
07-08 17:04:34.978: E/AndroidRuntime(322): at com.gurpswu.gurps.Home.hudSetup(Home.java:102)
07-08 17:04:34.978: E/AndroidRuntime(322): at com.gurpswu.gurps.Home.onCreate(Home.java:25)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-08 17:04:34.978: E/AndroidRuntime(322): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-08 17:04:34.978: E/AndroidRuntime(322): ... 11 more
I have a game. When the user opens the app for the first time and presses the continue game button..the game will attempt to retrieve values from the database using the code below.
stats.open();
playerId = stats.getIntField(stats.KEY_ROWID);
String playerName = stats.getStringField(stats.KEY_NAME);
String playerCity = stats.getStringField(stats.KEY_CITY);
playerHealth = stats.getIntField(stats.KEY_HEALTH);
playerEnergy = stats.getIntField(stats.KEY_ENERGY);
playerRank = stats.getIntField(stats.KEY_RANK);
playerCash = stats.getIntField(stats.KEY_CASH);
stats.close();
However, none of these database fields are populated…how do install a check..so that this code is only run if a database exists. If it does not exist then it will ask the player to start a new game.
there must be a check on
statsafter you dostats.open(), you should call something which returns number of rows. you can put a condition if rows are 0.or you can have try catch with NullPExe