title: Retrieve data from SQLite in RecyclerView inside fragment
body: <p>I have an activity that contain custom <code>Tablayout</code>.</p>
  
  <p>the <code>Tablayot</code> has <code>pageViewer</code> and link to a fragment.</p>
  
  <p>I want to show data from my <code>SQLite</code> database in <code>RecyclerView</code> in fragment.</p>
  
  <p>this is my codes:</p>
  
  <p>DatabaseHelper.java:</p>
  
  <pre><code>package ir.shirazmetro;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DatabaseHelper extends SQLiteOpenHelper {
  private static final String TAG = "DatabaseHelper";
  
  public static final String DATABASE_NAME = "MetroDB.db";
  public static final String TABLE_NAME = "estation";
  public static final String COL_1 = "station";
  public static final String COL_2 = "time";
  public static final String COL_3 = "line";
  
  public DatabaseHelper(Context context) {
      super(context, DATABASE_NAME, null, 1);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      db.execSQL("create table " + TABLE_NAME + " (COL_1,COL_2,COL_3)");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
      onCreate(db);
  }
  
  public boolean insertData(String station, String time, String line) {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues contentValues = new ContentValues();
      contentValues.put(COL_2, time);
      long result = db.insert(TABLE_NAME, null, contentValues);
      if (result == -1)
          return false;
      else
          return true;
  }
  
  
  public Cursor getData() {
      SQLiteDatabase db = this.getWritableDatabase();
      return db.rawQuery("select "+COL_2+" from " + TABLE_NAME, null);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My activity(station.java):</p>
  
  <pre><code>package ir.shirazmetro.views.activities;
  import android.content.Intent;
  import android.support.v4.view.ViewPager;
  import android.support.design.widget.TabLayout;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.View;
  import java.util.ArrayList;
  import java.util.List;
  import ir.shirazmetro.DatabaseHelper;
  import ir.shirazmetro.R;
  import ir.shirazmetro.other.components.ButtonCell;
  import ir.shirazmetro.other.components.TextViewCell;
  import ir.shirazmetro.views.adapters.BasePagerAdapter;
  import ir.shirazmetro.views.adapters.MoviesAdapter;
  
  public class estation extends BaseActivity {
  Toolbar mToolbar;
  private TabLayout tbLayout;
  private ViewPager vPager;
  
  private List&lt;DatabaseHelper&gt; movies = new ArrayList&lt;DatabaseHelper&gt;();
  private RecyclerView recyclerView;
  private MoviesAdapter adapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_estation);
  
      mToolbar = findViewById(R.id.tlbr1);
  
      setSupportActionBar(mToolbar);
  
          initView();
          setupWithViewPager();
          tbLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
  
              }
          });
  
          recyclerView = findViewById(R.id.myRecycler);
          adapter = new MoviesAdapter(movies);
  
          recyclerView.setLayoutManager(new LinearLayoutManager(estation.this));
          recyclerView.setAdapter(adapter);
          DatabaseHelper getData = (DatabaseHelper) new DatabaseHelper(this).getData();
          movies.add(getData);
          adapter.notifyDataSetChanged();
  
      }
  
  }
  
  private void setupWithViewPager() {
      BasePagerAdapter basePagerAdapter = new BasePagerAdapter(this, getSupportFragmentManager());
      vPager.setAdapter(basePagerAdapter);
      tbLayout.setupWithViewPager(vPager);
  
  }
  
  private void initView() {
      vPager = findViewById(R.id.view_pager);
      tbLayout = findViewById(R.id.tab_layout);
      backBtn = findViewById(R.id.backBtn);
  
      backBtn.setOnClickListener((View.OnClickListener) this);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and this code is my Adapter:</p>
  
  <pre><code>package ir.shira.views.adapters;
  
  import android.content.Context;
  import android.support.annotation.NonNull;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import java.util.List;
  import ir.shira.DatabaseHelper;
  import ir.shira.R;
  import ir.shira.models.movie;
  
  
  public class MoviesAdapter extends RecyclerView.Adapter&lt;MoviesAdapter.MovieViewHolder&gt; {
  
  private List&lt;movie&gt; movies;
  private Context context;
  
  public MoviesAdapter(List&lt;DatabaseHelper&gt; movies) {
      movies = movies;
  }
  @NonNull
  @Override
  public MovieViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_to_dastgheyb,parent,false);
      return new MovieViewHolder(view);
  }
  @Override
  public void onBindViewHolder(@NonNull MovieViewHolder holder, int position) {
      holder.txtTime.setText(movies.get(position).getTime());
  }
  @Override
  public int getItemCount() {
      return movies.size();
  }
  public class MovieViewHolder extends RecyclerView.ViewHolder
  {
      public TextView txtTime;
  
      public MovieViewHolder(View itemView)
      {
          super(itemView);
          txtTime = itemView.findViewById(R.id.textView);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>my app crash when I  run the project, any ideas?</p>