2014-07-16 59 views
2

我正在用Xamarin.Forms製作一個Android應用程序。我的iOS應用程序已經完成併發布。 我的android版本不會停止拋出多個異常。第一個例外是NullReferenceException。在下面的代碼這打破剪斷:OnPropertyChanged在android中引發異常xamarin.forms應用程序

handler(this, new PropertyChangedEventArgs(propertyName)); 

這是我在我用我的模型定製NotifyBase類OnPropertyChanged方法內。 (也沒有,如果我刪除所有,但由法這一行。)

調試輸出只是告訴我:

System.NullReferenceException: Object reference not set to an instance of an object 
An unhandled exception occured. 
Exception: 

其次是一個TargetInvocationException給這個堆棧跟蹤:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
07-16 17:37:47.916 I/MonoDroid(27212): UNHANDLED EXCEPTION:  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object 
07-16 17:37:47.916 I/MonoDroid(27212):07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName) [0x00087] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:68 
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Helper.NotifyBase.SetField[DateTime] (System.DateTime& field, DateTime value, System.String propertyName) [0x000a2] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:102 
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Core.TransMissionCore.set_Date (DateTime value) [0x00001] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Core\TransMissionCore.cs:275 
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) 
07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
07-16 17:37:47.916 I/MonoDroid(27212): --- End of inner exception stack trace --- 
07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00062, 0x0033c> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MethodBase.Invoke (object,object[]) <IL 0x00006, 0x0008f> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00295, 0x0162f> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x0018b> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (bool) <IL 0x00027, 0x00113> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject/<>c__DisplayClass1.<SetValueCore>b__0() <IL 0x00100, 0x00493> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x001b4, 0x009d3> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x001f1, 0x011db> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0007e, 0x003bf> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0004d, 0x00237> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.ApplyBindings (object) <IL 0x0003a, 0x002af> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x00056, 0x0029b> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnBindingContextChanged() <IL 0x0001c, 0x00157> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.View.OnBindingContextChanged() <IL 0x0003b, 0x002a3> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x0005c, 0x002bf> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element) <IL 0x00020, 0x00107> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element) <IL 0x00002, 0x00053> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.OnInternalAdded (Xamarin.Forms.VisualElement) <IL 0x00015, 0x000bf> 
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionC 

未處理的異常:

再次後跟一個TargetInvocationException給該堆棧跟蹤:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
07-16 17:41:19.182 E/mono (27212): 
07-16 17:41:19.182 E/mono (27212): Unhandled Exception: 
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.Compon07-16 17:41:19.182 E/mono (27212): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object 
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:41:19.182 E/mono (27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName 
07-16 17:41:19.182 E/mono-rt (27212): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object 
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0 
07-16 17:41:19.182 E/mono-rt (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:41:19.182 E/mono-rt (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 
07-16 17:41:19.182 E/mono-rt (27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String 
Das Programm "Mono" wurde mit Code 0 (0x0) beendet. 

正如我調試輸出狀態,這似乎發生了被設置爲似乎是對的DatePicker一個最小值一個DateTime屬性:

07-16 17:32:45.761 I/mono-stdout(27212): DEBUG  - Changing value from '01.01.0001 00:00:00' to '01.01.1900 00:00:00'. 
07-16 17:32:45.771 I/mono-stdout(27212): DEBUG  - Raising PropertyChanged for: 'TransMissionCore.Date'. 

我的代碼完美地工作在iOS。但在Android上這是一個展示瓶塞。 我用最新版本的Xamarin.Forms(1.2.1.6229)和1.1.1.6206來試用我的應用程序,但這沒什麼區別。

是否有某種解決方法?或者我犯了一個錯誤? 請給出建議。

+0

如果處理程序爲空,您確定Android代碼正在訂閱事件嗎? – SKall

+0

你有沒有檢查你的datamodel屬性和你的轉換器(如果有的話)?我敢打賭,NullReferenceException在你的代碼中。 – ad1Dima

+0

處理程序不爲null。並且Property也不爲null。 'DateTime'不能爲空。沒有轉換器參與。正如Xamarin團隊在他們的論壇上回答的,這是一個已知的錯誤。 – FrTerstappen

回答

2

這是在最新版本的xamarin表單中修復的。 我沒有把足夠的注意力放在最新版本的異常堆棧跟蹤上。 我認爲堆棧軌跡是相同的,但它們在某些部分有所不同 這似乎有另一個來源,來自我的應用程序的另一部分。