我试图在扩展应用程序的类中添加Xamarin.Forms.Init()
,但它在下面给出了一个错误:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it.
at Xamarin.Forms.Device.get_PlatformServices () [0x00007] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Device.cs:79
at Xamarin.Forms.Device.GetAssemblies () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Device.cs:161
at Xamarin.Forms.DependencyService.Initialize () [0x00008] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\DependencyService.cs:72
at Xamarin.Forms.DependencyService.Get[T] (Xamarin.Forms.DependencyFetchTarget fetchTarget) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\DependencyService.cs:18
at Diabetes.localDB.MedicationDatabase..ctor () [0x00008] in /Users/haleem/Projects/Diabetes/Diabetes/localDB/MedicationDatabase.cs:15
at Diabetes.Droid.MainApplication..ctor (System.IntPtr handle, Android.Runtime.JniHandleOwnership transer) [0x00000] in /Users/haleem/Projects/Diabetes/Droid/MainApplication.cs:27
at at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
--- End of inner exception stack trace ---
现在正在寻找添加Xamarin.Forms.Init()
的方法,以下是我的代码:
public class MainApplication : Application
{
ISetAlarm alarmService;
MedicationDatabase db = new MedicationDatabase();
public MainApplication()
{
}
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
//global::Xamarin.Forms.Forms.Init(this);
Xamarin.Forms.Init();
alarmService = new SetAlarmImplementation();
var alarm_list = db.GetAlarmList();
//Debug.WriteLine(" Time -- : "+ m.ToString());
var message = "Hello Its I remind you to take insulin";
var title = "Diabetics App";
foreach (var list in alarm_list)
{
var hour = Int32.Parse(list.Substring(0, 2));
var minute = Int32.Parse(list.Substring(3, 2));
alarmService.SetAlarm(hour, minute, title, message);
// Create your application here
}
}
}
如何将其添加到那里请在应用程序
中使用