I have a class named DatabaseManager, that contains the following code:
private SQLiteConnection _connection;
public DatabaseManager()
{
_connection = DependencyService.Get<ISQLite>().GetConnection();
_connection.CreateTable<User>();
}
The Android specific implementation of the GetConnection does not throw any exceptions or erros, but after adding debug messages to that code, it seems the App does not even get to that point. Below is the android method:
public SQLite.SQLiteConnection GetConnection ()
{
var sqliteFilename = "SQLite.db3";
string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); // Documents folder
var path = Path.Combine(documentsPath, sqliteFilename);
// Create the connection
var conn = new SQLite.SQLiteConnection(path);
// Return the database connection
return conn;
}
I am declaring my database in a public static class, so that I can use it multiple different Xamarin Forms without having to pass it around. It is declared like this:
public static class database
{
public static DatabaseManager db = new DatabaseManager();
}
The exception thrown says:
02-03 11:35:15.898 E/AndroidRuntime( 2117): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'RegistrationApp.database' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object 02-03 11:35:15.898 E/AndroidRuntime( 2117): at RegistrationApp.Data.DatabaseManager..ctor () <0xd95e3268 + 0x0001b> in <filename unknown>:0 02-03 11:35:15.898 E/AndroidRuntime( 2117): at RegistrationApp.database..cctor () <0xd95e3230 + 0x0001f> in <filename unknown>:0 02-03 11:35:15.898 E/AndroidRuntime( 2117): --- End of inner exception stack trace ---
It seems there is some kind of Null reference in the constructor, but I do not know what the exact problem is?
Aucun commentaire:
Enregistrer un commentaire