title: android code to fetch data from database
body: <pre><code>    ParsedNotificationDataSet result = new ParsedNotificationDataSet();
      Cursor c = db.rawQuery("select * from notificationtable", null);
      if (c.getCount() &gt; 0) {
          c.moveToFirst();
          do {
              result.setclassurl(c.getString(c.getColumnIndex("Id")));
              result.settype(c.getString(c.getColumnIndex("type")));
              result.setschool(c.getString(c.getColumnIndex("school")));
              result.setdescription(c.getString(c.getColumnIndex("description")));
              result.settitle(c.getString(c.getColumnIndex("title")));
              result.setdatePosted(c.getString(c.getColumnIndex("datePosted")));
              results.add(result);
          } while (c.moveToNext());
      }
  </code></pre>
  
  <p>Here is my code to fetch data from the database. In my opinion it should work properly but at the very first time it generates a <code>java.lang.NullPointerException</code> exception. After that it runs without a problem. What modifications do I need to make to resolve this issue?</p>