Q:

Android showing database in SwipeView

I have a swipeview with two different views(fragments) via a viewpager. I now want these two pages to show different data from an sqllite database. The Problem is i cant figure out how to do this, from the main activity i am not able to access the views (TableLayout) on my fragments and from the fragments sourcecode i cant access the database because the adapter wont open (context of adapter is super.getActivity()). Is there any way to do this?
Code of the Fragment:
DBAdapter adapter = new DBAdapter(getActivity());

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    if(container==null){
        return null;
    }

    layout=(RelativeLayout)inflater.inflate(R.layout.layout_morning, container, false);

    adapter.open();
    adapter.close();

Code of DBAdapter:
    private static String DB_NAME = "database.dat";

private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;

public DBAdapter(Context ctx) {
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper {

    DatabaseHelper(Context context) {
        super(context, DB_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

public DBAdapter open() throws SQLException {

    db = DBHelper.getWritableDatabase();
    return this;
}

public void close() {
    if (db!=null){
        db.close();
    }
    DBHelper.close();
}

Error is a NullPointerException

A:

of course you can access a database inside a fragment, you just need to use getActivity(); instead of this.
Example to save an image file inside a fragment class:
db = new DatabaseHandler(getActivity());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
db.updateUser(imageInByte);
db.close();

