title: Android adapter context
body: <p>New to Android dev and trying to get Context in my application adapter but I keep getting null exceptions. My attempt it to load the url string into glide, but <code>glide.with(context)</code> isn't working. The application pulls values from sqlite (this part works fine), I'm now trying to get one of those values (url) and set it to the imageview via glide. The XML has all the views required. </p>
  
  <p>error: <strong>You cannot start a load on a null Context at com.bumptech.glide.manager.RequestManagerRetriever.get</strong></p>
  
  <p><strong>UsersAdapter.java</strong></p>
  
  <pre><code>public class UsersAdapter extends RecyclerView.Adapter&lt;UsersAdapter.UserViewHolder&gt; {
  private ArrayList&lt;User&gt; mDataSet;
  
  public UsersAdapter(ArrayList&lt;User&gt; mDataSet) {
      this.mDataSet = mDataSet;
  }
  
  @Override
  public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_favorites2, parent, false);
      UserViewHolder userViewHolder = new UserViewHolder(v);
      return userViewHolder;
  }
  
  @Override
  public void onBindViewHolder(UserViewHolder holder, int position) {
  
      holder.name_entry.setText(mDataSet.get(position).getName());
      holder.email_entry.setText(mDataSet.get(position).getEmail());
      holder.icon_entry.setText(""+mDataSet.get(position).getName().charAt(0));
  
      String name = mDataSet.get(position).getName();
      String url = mDataSet.get(position).getEmail();
  
      // load image into imageview using glide
      Glide.with(context)
              .load(url)
              .asBitmap()
              .placeholder(R.drawable.ic_blank)
              .error(R.drawable.ic_blank)
              .into(holder.ivFavorites);
  }
  
  @Override
  public int getItemCount() {
      return mDataSet.size();
  }
  
  public class UserViewHolder extends RecyclerView.ViewHolder {
      CardView cardView;
      TextView name_entry, email_entry, icon_entry;
      ImageView ivFavorites;
  
      UserViewHolder(View itemView) {
          super(itemView);
          cardView = (CardView) itemView.findViewById(R.id.user_layout);
          name_entry = (TextView) itemView.findViewById(R.id.name_entry);
          email_entry = (TextView) itemView.findViewById(R.id.email_entry);
          icon_entry = (TextView) itemView.findViewById(R.id.icon_entry);
          ivFavorites = (ImageView) itemView.findViewById(R.id.ivFavorites);
      }
  }
  
  @Override
  public void onAttachedToRecyclerView(RecyclerView recyclerView) {
      super.onAttachedToRecyclerView(recyclerView);
  }
  }
  </code></pre>
  
  <p>Reading about adapters and Context I tried the following but with minimal success.</p>
  
  <pre><code>public class UsersAdapter extends      RecyclerView.Adapter&lt;UsersAdapter.UserViewHolder&gt; {
  private ArrayList&lt;User&gt; mDataSet;
  private Context context;
  public UsersAdapter(ArrayList&lt;User&gt; mDataSet) {
      this.mDataSet = mDataSet;
  }
  public UsersAdapter(ArrayList&lt;User&gt; mDataSet, Context context) {
      this.context = context;
  }
  </code></pre>
  
  <p>My <strong>Favorites.java</strong> activity which pulls the values from sqlite and displays them in cardview (this also works fine, although I can't get glide to load the image):</p>
  
  <p>public class Favorites extends AppCompatActivity {</p>
  
  <pre><code>private RecyclerView recyclerView;
  private LinearLayoutManager layoutManager;
  private UsersAdapter adapter;
  private DBHandler dbHandler;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_favorites);
      recyclerView = (RecyclerView) findViewById(R.id.usersList);
      recyclerView.setHasFixedSize(true);
      layoutManager = new GridLayoutManager(this,2);
      recyclerView.setLayoutManager(layoutManager);
      dbHandler = new DBHandler(Favorites.this);
  
      Log.d("Reading: ", "reading contacts..");
      ArrayList&lt;User&gt; users = dbHandler.getAllUsers();
      adapter = new UsersAdapter(users);
      recyclerView.setAdapter(adapter);
      adapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>}</p>