on 2013 Jan 14 4:24 PM
Hello, I have a working Mobilink synchronization in my Android app. Everything works fine until I stop the wi-fi of my phone. Then appears a strange error(but not always, sometimes I get only the Mobilink communication error which is handled without a problem with try and catch):
01-14 22:54:08.698: E/AndroidRuntime(1374): FATAL EXCEPTION: LocalService
01-14 22:54:08.698: E/AndroidRuntime(1374): java.lang.NullPointerException
01-14 22:54:08.698: E/AndroidRuntime(1374): at DAL.DBUtil.SyncVouchers(DBUtil.java:434)
01-14 22:54:08.698: E/AndroidRuntime(1374): at com.mycompany.myapp.LocalService$1.run(LocalService.java:62)
01-14 22:54:08.698: E/AndroidRuntime(1374): at java.lang.Thread.run(Thread.java:864)
Here is the source code where the error appears, it is called from a service that is started with alarm manager, the exception is thrown always at SetPort method:
try { Connection conn = DBUtil.CreateConnection(context); try { SyncParms syncParms = conn.createSyncParms( SyncParms.HTTP_STREAM, "user", "Version"); syncParms.getStreamParms().setHost(PreferencesUtil.IP); syncParms.getStreamParms().setPort(PreferencesUtil.Port); syncParms.setPublications("myPublication"); syncParms.setAuthenticationParms(String .valueOf(app_settings.CurrentUserID)); conn.synchronize(syncParms); conn.commit(); } finally { conn.release(); } } catch (ULjException ex) { ex.printStackTrace(); } catch (Error er) { er.printStackTrace(); }}
And despite i have catch block at the end, the application crashes and doesn't handle the error.. After that the alarm manager is still being called but in log cat appears - Unable to launch app... process is bad. Do you have any idea what is happening?
I finally got it! Thanks to Graham Hurst 🙂 When I stop the Wi-Fi I got the ordinary connection exception once and after that all static variables are lost and I got null reference exceptions. The solution was to save the variables that I need in SharedPreferences and take them every time the service is started.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are never catching the NullPointerException
because it is not an instance of either Error
or ULjException
, and you are only catching those. It is an instance of RuntimeException
, so is an unchecked exception and does not need to be in a method or constructor's throws
clause.
Instead of calling syncParms.getStreamParms()
twice, why not assign it to a variable that you can test for nullness before calling setHost()
and setPort()
.
StreamParms streamParms = syncParms.getStreamParms(); if ( streamParms != null ) { streamParms.setHost(PreferencesUtil.IP); streamParms.setPort(PreferencesUtil.Port); } else { // Handle null streamParms }
However I doubt that would fix the underlying problem, unless it is due to garbage collection occuring between your two calls to getStreamParms().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
66 | |
11 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.