title: android sqlite database, null pointer
body: <p>I am trying to get and set info into my database but it keeps returning null. </p>
  
  <p>I tested it and it seems to be something wrong with my <code>DatabaseHelper</code> class and how I'm using it. This is my <code>DatabaseHelper</code> class. The database itself is already made using a sqlite database manager and is in the assets folder.</p>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper{
  
  private static String DB_PATH = "/data/data/package_name/databases/";
  
  private static String DB_NAME = "example.db";
  private static int DB_VERSION = 1;
  
  private SQLiteDatabase myDataBase; 
  
  private final Context myContext;
  
  
  public DatabaseHelper(Context context) {
      super(context, DB_NAME, null, DB_VERSION);
      this.myContext = context;
  }   
  
  
  public void createDataBase() throws IOException{
  
      boolean dbExist = checkDataBase();
  
      if(dbExist){
      }else{
  
  
       with our database.
          this.getReadableDatabase();
  
          try {
  
              copyDataBase();
  
          } catch (IOException e) {
  
              throw new Error("Error copying database");
  
          }
      }
  
  }
  
  
    private boolean checkDataBase(){
  
      SQLiteDatabase checkDB = null;
  
      try{
          String myPath = DB_PATH + DB_NAME;
          checkDB = SQLiteDatabase.openDatabase(myPath, null, 
      SQLiteDatabase.OPEN_READONLY);
  
      }catch(SQLiteException e){
  
  
      }
  
      if(checkDB != null){
  
          checkDB.close();
  
      }
  
      return checkDB != null ? true : false;
    }
  
  
    private void copyDataBase() throws IOException{
  
      InputStream myInput = myContext.getAssets().open(DB_NAME);
  
      String outFileName = DB_PATH + DB_NAME;
  
      OutputStream myOutput = new FileOutputStream(outFileName);
  
      byte[] buffer = new byte[1024];
      int length;
      while ((length = myInput.read(buffer))&gt;0){
          myOutput.write(buffer, 0, length);
      }
  
      myOutput.flush();
      myOutput.close();
      myInput.close();
  
  }
  
  
      public void openDataBase() throws SQLException{
  
      String myPath = DB_PATH + DB_NAME;
      myDataBase = SQLiteDatabase.openDatabase(myPath, null, 
     SQLiteDatabase.OPEN_READWRITE);
  
  
         }
  
     public void setStuff (String columns, String table, String values, String              
     whereclause){
      openDataBase();
      myDataBase.execSQL("INSERT INTO "
               + table
               + " "+columns
               + " VALUES ('"+values+")" + " WHERE "+whereclause);
      close();
  
     }
  
     public ArrayList&lt;String&gt; getStuff (String column, String table, String whereclause){
      ArrayList&lt;String&gt; stuffList = new ArrayList&lt;String&gt;();
      openDataBase();
      Cursor c = myDataBase.rawQuery("SELECT "+column +
              " FROM " +table
              + " WHERE "+whereclause,
              null);
      int index = c.getColumnIndex(column);
       if (c != null) {
           if (c.isFirst()) {
                   do {
  
                           String stuff = c.getString(index).toString();
                           results.add(data);
                   } while (c.getString(index)!=null);
           }
       }
       close();
       return stuffList;
  
  
  }
  
  
     @Override
  public synchronized void close() {
  
          if(myDataBase != null)
              myDataBase.close();
  
          super.close();
  
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      try {
          createDataBase();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  
  
  
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
  }
  
  
  }
  </code></pre>
  
  <p>Next my class that actually tries to use this database helper is for example, my <code>PersonDBController</code> class, which is in turned used in my signUp activity, where i just call the method with the parameters.</p>
  
  <pre><code>        public class PersonDBController {
              private DatabaseHelper d;
              private Person p;   
  
  
                  public String getFirstname(int userIDnum) {
                          ArrayList&lt;String&gt; fn = 
                                                        d.getStuff("firstname", 
                                                        "people", "userIDnum     
                                                         ="+userIDnum);
                          String result = fn.get(0);
                          return result;
                      }
  </code></pre>
  
  <p>Thats just one of many methods in that class. However, this doesn't do the job properly. When called in an activity - say on a button click to set or get stuff it returns a null pointer exception. </p>
  
  <p>Any idea what im doing wrong? </p>