title: Null pointer exception when loading items to the spinner
body: <p>This is my activity class,where I have spinner.I need to load the database values to the spinner,So Using ArrayList and ArrayAdapter,I did that.</p>
  
  <p>But when I run my app,It's giving Null pointer exception. </p>
  
  <pre><code>public class addexpense extends ActionBarActivity {
  
      DBhelper helper;
      SQLiteDatabase db;
      Spinner spinner;
  
      @Override
      /** Called when the activity is first created. */
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
          setContentView(R.layout.addexpenses);
  
  
          ArrayList&lt;category&gt; mArrayList = helper.getCategories();
          Spinner sp =(Spinner)findViewById(R.id.spinner);
          ArrayAdapter adapter =new ArrayAdapter(this,R.layout.spinner_row,mArrayList);
         sp.setAdapter(adapter);
  
     }
  
  }
  </code></pre>
  
  <p>This is my method in DBHelper database class</p>
  
  <pre><code>     public class DBhelper extends SQLiteOpenHelper{
  
      static final String DATABASE = "wedding9.db";
      static final int VERSION = 9;
      static final String TABLE1 = "Category";
      static final String TABLE2 = "Budget";
  
  
      static final String C_ID = "_id";
      static final String Name = "name";
      static final String B_ID = "_id";
      static final String Description = "description";
      static final String Amount = "amount";
  
  
  
      public DBhelper(Context context){
          super(context, DATABASE, null, VERSION);
      }
  
      public void onCreate(SQLiteDatabase db){
  
          db.execSQL("CREATE TABLE " + TABLE1+ "(" +C_ID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT," +Name+ " text unique not null)");
  
          db.execSQL("CREATE TABLE " + TABLE2+ "(" +B_ID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT," +Description+ " text,"
                  +Amount+ " text, FOREIGN KEY ("+Description+") REFERENCES "+TABLE1+"("+Name+"));");
  //        db.execSQL("CREATE TABLE " + TABLE2+ "(" +B_ID
  //                + " INTEGER PRIMARY KEY AUTOINCREMENT," +Amount+ " text )");
  
  
      }
  
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
          db.execSQL("drop table " + TABLE1);
  
  
          onCreate(db);
      }
  
      public ArrayList&lt;category&gt; getCategories(){
          ArrayList&lt;category&gt; arrayList = new ArrayList&lt;category&gt;();
          SQLiteDatabase db = getReadableDatabase();
          Cursor c = db.query(DBhelper.TABLE1, null, null, null, null, null, null);
  //        c.moveToFirst();
          while (c.moveToNext()) {
              category cat = new category(c.getInt(0),c.getString(1));
              arrayList.add(cat);
          }
  
          return arrayList;
      }
      public boolean checkIdExist(String name) {
          SQLiteDatabase db = getReadableDatabase();
          Cursor c = db.query(DBhelper.TABLE1, null, null, null, null, null, null);
  //        c.moveToFirst();
          while (c.moveToNext()) {
              if(c.getString(1).equals(name))
                  return false;
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>This is the category class</p>
  
  <pre><code>public class category
  {
      private int id;
      private String name;
  
      public category(int id, String name) {
          this.id = id;
          this.name = name;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>Below one is the exception,I got when I run the app</p>
  
  <blockquote>
    <p>10-23 08:29:21.482    3075-3075/com.example.username.weddingplanning
    E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.username.weddingplanning/com.example.username.weddingplanning.addexpense}:
    java.lang.NullPointerException
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2250)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2304)
                at android.app.ActivityThread.access$700(ActivityThread.java:152)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:176)
                at android.app.ActivityThread.main(ActivityThread.java:5299)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.NullPointerException
                at com.example.username.weddingplanning.addexpense.onCreate(addexpense.java:43)
                at android.app.Activity.performCreate(Activity.java:5326)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2304)
                at android.app.ActivityThread.access$700(ActivityThread.java:152)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:176)
                at android.app.ActivityThread.main(ActivityThread.java:5299)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>