I released a game on the android market recently and got my first error report through ACRA today. The exception is:
java.lang.NullPointerException
at com.sweee.db.AndroidDBHelper.java.util.ArrayList getScores()(SourceFile:65)
at sweee.com.screens.HighScoreScreen.void show()(SourceFile:180)
at com.badlogic.gdx.Game.void setScreen(com.badlogic.gdx.Screen)(SourceFile:59)
at sweee.com.screens.LevelDoneScreen.void render$133aeb()(SourceFile:46)
at com.badlogic.gdx.Game.void render()(SourceFile:46)
at com.sweee.main.SweeeMain.void render()(SourceFile:125)
at com.badlogic.gdx.backends.android.AndroidGraphics.void
onDrawFrame(javax.microedition.khronos.opengles.GL10)(SourceFile:452)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
Through ACRA I know the device was an Acer Iconia A100 with ICS 4.03 running. I unfortuntly cannot reproduce the error on the emulator (tried connected to the internet and airplane mode). The line on which it claims to throw the NPE, is a call to my Function “isConnected()” which does this:
public boolean isConnected() {
final ConnectivityManager connectManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// Return true if connected, either in 3G or wi-fi
final boolean connected = (connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connectManager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED);
return connected;
}
I am pretty much clueless and would like to fix this bug. Is there any general problem with this method to check for an existing internet connection that is specific to ICS 4.03 or the Iconia A100?
Maybe someone who owns an Iconia A100 could do me a favor and try to reproduce the failure? The game is free on android market here. Thank you very much for your time and any possible answer or hint.
edit:
@Override
public ArrayList<Score> getScores() {
Cursor c = getWritableDatabase().query("scores", null, null, null, null, null, "points DESC");
if (c.moveToFirst()) {
do {
Score s = new Score(c.getString(1), c.getInt(2), getBoolFromInt(c.getInt(3)), getBoolFromInt(c.getInt(4)));
if (!scores.contains(s)) {
scores.add(s);
}
} while (c.moveToNext());
}
if (isConnected()) {
syncDB();
}
return scores;
}
this is the function that causes the NPE. Line 65 would be
if(isConnected()) {
the ArrayList scores is instantiated when the class gets (one of the first calls of the app, this does not get called before, should therefore not be null).
neither a call to scores.contains(s) nor add should cause a NPE, right?
I just don’t get it. Especially as this code is running fine on meanwhile 9 other devices…
I really appreciate any more help. Thanks!
I think the error is on this line
That happens because
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);returns null.Look at the documentation. It says
According to this, the nameReturns: The service or null if the name does not exist.
Context.CONNECTIVITY_SERVICEdoes not exist. Could it be an OS implementation issue? Probably.I had a somewhat “similar” situation: I wanted to start an activity to handle the
android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS, and on my device it worked (OS 2.3.7), but on some other devices (OS version above and below 2.3.7) it didn’t work. Could it be an OS implementation issue? Most likely.Since you can not reproduce the crash,
Acer Iconia A100 with ICS 4.03and test on itRelease an update with the following code and hope that your user with the Acer Iconia updates the app:
This way you could get a crash report with this specific message. This way you could deduce some conclusions.
Anyway, if you just want to make your app work, check
connectManageragainstnull.Hope this helps.
EDIT:
Or, just do the following:
and see if the stacktrace is the same.