Note that there are some explanatory texts on larger screens.

plurals
  1. PONullReferenceException when page Loads
    text
    copied!<p>I load a list from a <code>SQLite</code> database when my page loads and sometimes when it loads I get <code>NullReferenceException</code> with the error saying <code>Object reference not set to an instance of an object.</code></p> <p>it breaks in this code in the SQLite class file</p> <pre><code>public TableMapping GetMapping (Type type) { if (_mappings == null) { _mappings = new Dictionary&lt;string, TableMapping&gt; (); } TableMapping map; if (!_mappings.TryGetValue (type.FullName, out map)) { map = new TableMapping (type); _mappings [type.FullName] = map; //null here } return map; } </code></pre> <p>This is what I do when my page loads</p> <pre><code>public MainPage() { this.InitializeComponent(); Loaded += MainPage_Loaded; } void MainPage_Loaded(object sender, RoutedEventArgs e) { createDatabase(); getBowlers(); } private async void createDatabase() { SQLiteAsyncConnection conn = new SQLiteAsyncConnection(BOWLERS_DATABASE); await conn.CreateTableAsync&lt;Bowler&gt;(); conn = new SQLiteAsyncConnection(GAMES_DATABASE); await conn.CreateTableAsync&lt;Games&gt;(); } private async void getBowlers() { SQLiteAsyncConnection conn = new SQLiteAsyncConnection(BOWLERS_DATABASE); var query = conn.Table&lt;Bowler&gt;(); itemListView.DataContext = await query.ToListAsync(); } </code></pre> <p>I am new to page lifecycle but it seems that I am trying to pull from the database to early possibly? </p> <p>EDIT</p> <p>stacktrace</p> <pre><code>System.NullReferenceException was unhandled by user code HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=mscorlib StackTrace: at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value) at SQLite.SQLiteConnection.GetMapping(Type type) in c:\Users\Jeff\Dropbox\Tournament Director Windows\Tournament Director Windows\SQLite.cs:line 231 at SQLite.TableQuery`1..ctor(SQLiteConnection conn) in c:\Users\Jeff\Dropbox\Tournament Director Windows\Tournament Director Windows\SQLite.cs:line 2129 at SQLite.SQLiteConnection.Table[T]() in c:\Users\Jeff\Dropbox\Tournament Director Windows\Tournament Director Windows\SQLite.cs:line 616 at SQLite.SQLiteAsyncConnection.Table[T]() in c:\Users\Jeff\Dropbox\Tournament Director Windows\Tournament Director Windows\SQLiteAsync.cs:line 260 at Tournament_Director_Windows.MainPage.&lt;getBowlers&gt;d__c.MoveNext() in c:\Users\Jeff\Dropbox\Tournament Director Windows\Tournament Director Windows\MainPage.xaml.cs:line 116 InnerException: </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload