title: How to add data from a database to a recycler view using a cursor adapter?
body: <p>So I have tried implementing my database with a recycler view and cursoradapter, but I am getting errors. I can not understand them well so I dont know if I did not implement the adapter right or if it is something else. Here are the java files:</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      public static final String EXTRA_MESSAGE = "com.nick.mowen.receiptmanager.LOCATION";
      public String Places[];
      public RecyclerView RV;
      private RVAdapter adapter;
      Cursor mCursor;
      ManagerDatabaseAdapter managerDatabaseAdapter;
      List&lt;MainInfo&gt; mainInfo = new ArrayList&lt;MainInfo&gt;();
      RecyclerView.LayoutManager layoutManager;
      private Context activity;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          managerDatabaseAdapter = new ManagerDatabaseAdapter(this);
          setContentView(R.layout.activity_main);
          adapter = new RVAdapter(getActivity(), managerDatabaseAdapter.getTheCursor());
          RV = (RecyclerView) findViewById(R.id.mainV);
          layoutManager = new LinearLayoutManager(getActivity());
          RV.setLayoutManager(layoutManager);
          RV.setAdapter(adapter);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
        //  getMenuInflater().inflate(R.menu.menu_main, li)
          return true;
      }
  
      public static void getData () {
  
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              Intent intent = new Intent(this,SettingsActivity.class);
              intent.putExtra(EXTRA_MESSAGE,true);
              startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      /*@Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          TextView userText= (TextView) view;
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
      }*/
  
      public void addInstance(View view) {
          Intent intent = new Intent(this,LocationAdder.class);
          intent.putExtra(EXTRA_MESSAGE,true);
          startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
      }
  
      public Context getActivity() {
          return activity;
      }
  }
  </code></pre>
  
  <p>Here is the recycler view adapter:</p>
  
  <pre><code>public class RVAdapter extends Adapter&lt;RVAdapter.MyViewHolder&gt; {
  
      private LayoutInflater inflater;
      CursorAdapter mCursorAdapter;
      Context mContext;
      //Cursor cursor;
      //public Cursor mCursor;
      MainInfo mainInfo;
      ManagerDatabaseAdapter.ManagerHelper managerHelper;
      public ManagerDatabaseAdapter managerDatabaseAdapter;
     // public List&lt;MainInfo&gt; mainInfoList = Collections.emptyList();
  
      public RVAdapter (Context context, Cursor cursor) {
          mContext = context;
          mCursorAdapter = new CursorAdapter(mContext, cursor, 0) {
              @Override
              public View newView(Context context, Cursor cursor, ViewGroup parent) {
                  //Cursor mCursor = getCursor();
  
                  final LayoutInflater inflater = LayoutInflater.from(context);
                  View view = inflater.inflate(R.layout.custom_row, parent, false);
  
                  int nameCol = cursor.getColumnIndex("Codes");
                  String name = cursor.getString(nameCol);
  
                  TextView nameText = (TextView) view.findViewById(R.id.mainV);
                  if (nameText != null) {
                      nameText.setText(name);
                  }
                  return view;
              }
  
              @Override
              public void bindView(View view, Context context, Cursor cursor) {
                  int nameCol = cursor.getColumnIndex("Code");
                  String name = cursor.getString(nameCol);
                  TextView nameText = (TextView) view.findViewById(R.id.mainV);
                  if (nameText != null) {
                      nameText.setText(name);
                  }
              }
          };
          //this.mainInfoList = mainInfoList;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = mCursorAdapter.newView(mContext, mCursorAdapter.getCursor(), parent);
          MyViewHolder holder = new MyViewHolder(view);
          return holder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int i) {
          /*MainInfo mainInfo = mainInfoList.get(i);
          holder.Title.setText(mainInfo.get_Title());
          holder.Body.setText(mainInfo.get_SubT());*/
          mCursorAdapter.bindView(holder.itemView, mContext, mCursorAdapter.getCursor());
      }
  
      @Override
      public int getItemCount() {
          //return mainInfoList.size();
          return mCursorAdapter.getCount();
      }
  
      class MyViewHolder extends RecyclerView.ViewHolder {
  
          TextView Title;
  
           MyViewHolder(View itemView) {
              super(itemView);
              Title = (TextView) itemView.findViewById(R.id.Row_Header);
              //Body = (TextView) itemView.findViewById(R.id.Row_Footer);
          }
      }
  }
  </code></pre>
  
  <p>Here is the method to get the cursor:</p>
  
  <pre><code>public Cursor getTheCursor() {
          String[] columns = {ManagerHelper.UID,ManagerHelper.NAME,ManagerHelper.CODE};
          SQLiteDatabase db = helper.getWritableDatabase();
          Cursor mCursor = db.query(ManagerHelper.TABLE_NAME, columns, null, null, null, null, null);
          return mCursor;
      }
  </code></pre>
  
  <p>And finally here is the error I am getting:</p>
  
  <p><a href="https://i.stack.imgur.com/szIz0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/szIz0.png" alt="Error"></a></p>