私のapp.xaml.csに私は新しいページを作成します。Xamarin.Forms.Init()を呼び出さなければなりません。それを使用する前に
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new WrapLayoutPage());
}
このページでは、DependencyServiceを使用していくつかのタスクを実行する静的クラスを呼び出します。
エラーがスローライン:
var tmpTable = SqLiteHelper.GetItem<TableX>("someId");
にSqLiteHelper:それが何らかの形で関連するのです
You MUST call Xamarin.Forms.Init(); prior to using it
:
public static class SqLiteHelper
{
private static readonly SQLiteConnection DatabaseConnection = DependencyService.Get<ISqLite>().GetConnection();
private static readonly object Locker = new object();
public static DbObjectV3 GetItem<T>(Guid inId) where T : DbObjectV3, new()
{
lock (Locker)
{
var tmpItem = DatabaseConnection.Table<T>().FirstOrDefault(inItem => inItem.Id == inId);
tmpItem.IsNewObject = false;
return tmpItem;
}
}
}
これは私のInnerExceptionとTypeInitializationException
をスローします静的ヘルパークラスは、その呼び出しの前に、私は何の問題もなくDependencyServiceを使用することができます。
私はスプラッシュ画面を使用しています。このクラスでは、私はDependencyServiceに依存するスタートアップ作業を行います。
スプラッシュ:
[Activity(Theme = "@style/MyTheme.Splash", NoHistory = true, MainLauncher = true)]
public class SplashScreen : Activity
{
static readonly string TAG = "X:" + typeof(SplashScreen).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
}
マイMainActivity:
[Activity(Label = "FrameworkForms", Icon = "@drawable/icon", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, Theme = "@style/MainActivityTheme", MainLauncher = false)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
App.ScreenWidth = (double)(Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density);
LoadApplication(new App());
}
}
今すぐFormsAppCompatActivityにスプラッシュ画面に活動を変更した後、私は別のエラーを取得します。
Call Forms.Init() before Hide Keyboard
ここには何がありますか?
あなたは_Xamarin.Forms_ライブラリの同じバージョンをAndroidおよび共有プロジェクトに持っていることを確認できますか? –
@PrashantCです。ちょうど最新バージョン(2.3.3.175)にアップグレードしました – greenhoorn
これはむしろ変です!これは新しいプロジェクトですか?新しいプロジェクトでそれは起こりますか? [診断ビルドの出力]を共有できますか(https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output) –