*Here is my code* [Activity] public class MainActivity : BaseRuattiActivity, ILocationListener { private LocationManager _lm; private bool _gpsEnabled; private bool _networkEnabled; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MainView); _lm = LocationManager.FromContext(this); _gpsEnabled = _lm.IsProviderEnabled(LocationManager.GpsProvider); _networkEnabled = _lm.IsProviderEnabled(LocationManager.NetworkProvider); }
protected override void OnResume() { base.OnResume(); if (_lm != null) { if (_gpsEnabled) _lm.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this, MainLooper); if (_networkEnabled) _lm.RequestLocationUpdates(LocationManager.NetworkProvider, 0, 0, this, MainLooper); } } protected override void OnPause() { if (_lm != null) { try { _lm.RemoveUpdates(this); } finally { _lm.Dispose(); _lm = null; } } base.OnPause(); } The problem is that periodically system throws Null Reference exception in OnPause method in try block and that killing my app. E/mono ( 4534): Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object E/mono ( 4534): at (wrapper delegate-invoke) <Module>:invoke_void__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) E/mono ( 4534): at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0 E/mono ( 4534): at Android.Locations.LocationManager.RemoveUpdates (ILocationListener listener) [0x00000] in <filename unknown>:0 E/mono ( 4534): at Ruatti.Gui.Modules.Main.MainActivity.OnPause () [0x00000] in <filename unknown>:0 E/mono ( 4534): at Android.App.Activity.n_OnPause (IntPtr jnienv, IntPtr native__this) [0x00000] in <filename unknown>:0 E/mono ( 4534): at (wrapper dynamic-method) object:e2437ed3-b5af-4d31-92a6-2ac61f5156ae (intptr,intptr) D/dalvikvm( 4534): threadid=1: thread exiting, not yet detached (count=0) E/dalvikvm( 4534): ERROR: detaching thread with interp frames (count=17) I/dalvikvm( 4534): "main" prio=5 tid=1 RUNNABLE I/dalvikvm( 4534): | group="main" sCount=0 dsCount=0 s=N obj=0x400208c0 self=0xcd40 I/dalvikvm( 4534): | sysTid=4534 nice=0 sched=0/0 cgrp=default handle=-1345017784 I/dalvikvm( 4534): at ruatti.gui.modules.main.MainActivity.n_onPause(Native Method) I/dalvikvm( 4534): at ruatti.gui.modules.main.MainActivity.onPause(MainActivity.java:61) I/dalvikvm( 4534): at android.app.Activity.performPause(Activity.java:3859) I/dalvikvm( 4534): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1190) I/dalvikvm( 4534): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3425) I/dalvikvm( 4534): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3395) I/dalvikvm( 4534): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3378) I/dalvikvm( 4534): at android.app.ActivityThread.access$2700(ActivityThread.java:129) I/dalvikvm( 4534): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2124) I/dalvikvm( 4534): at android.os.Handler.dispatchMessage(Handler.java:99) I/dalvikvm( 4534): at android.os.Looper.loop(Looper.java:143) I/dalvikvm( 4534): at android.app.ActivityThread.main(ActivityThread.java:4717) I/dalvikvm( 4534): at java.lang.reflect.Method.invokeNative(Native Method) I/dalvikvm( 4534): at java.lang.reflect.Method.invoke(Method.java:521) I/dalvikvm( 4534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) I/dalvikvm( 4534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) I/dalvikvm( 4534): at dalvik.system.NativeStart.main(Native Method) -- View this message in context: http://mono-for-android.1047100.n5.nabble.com/Error-with-LocationManager-tp4887681p4887681.html Sent from the Mono for Android mailing list archive at Nabble.com. _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid