我是Xamarin的新手。我想了解Sqlite并在我的项目上实现。昨天我没有收到任何错误,它已经工作了。今天我继续我的项目。但是当我开始编译时,出现异常处理错误消息。我不知道是什么错误我做。希望你们能帮我解决这个问题。
MainActivity.cs
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
namespace TravellerApp.Droid
{
[Activity(Label = "TravellerApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
//initialize Forms map
Xamarin.FormsMaps.Init(this, bundle);
string fileName = "travel_db.sqlite";
string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string fullPath = Path.Combine(folderPath, fileName);
LoadApplication(new App(fullPath));
}
}
}
App.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace TravellerApp
{
public partial class App : Application
{
public static string DatabaseLocation = string.Empty;
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
public App(String databaseLocation)
{
InitializeComponent();
//MainPage = new TravelRecordApp.MainPage();
MainPage = new NavigationPage(new MainPage());
DatabaseLocation = databaseLocation;
}
protected override void OnStart ()
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}