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 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. So it was the PreferencesUtil variables that became null?
(17 Jan '13, 18:58)
Graham Hurst
Yes, after getting an exception in the service all static properties become null..
(18 Jan '13, 03:25)
katalun4o
|
You are never catching the Instead of calling 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(). |
It is difficult to see from this code how syncParms or syncParms.getStreamParms() could be null at the setPort() line and not at the previous line. The setPort(int port) method simply assigns the integer argument to a member variable. I don't know what PreferencesUtil is, or whether it could be null.
In a nutshell, I don't have enough context to give an answer. You may have to open a support case and supply a small reproducible test.
PreferencesUtil is a simple class with methods to write in Preferences and Port and IP are static variables. I tried to check if syncParams == null and syncParams.getStreamParams() == null but I got the same exception again. I am very confused because the error is not catched by the Try/Catch block - always crashes