Intent error with private class

I am trying to call another class using intent. But it is not working. I am using android studio to implement this project.

The app should show a screen with logos of popular brands like amazon, google, twitter, facebook, etc. When a logo is clicked, it shows another screen(activity), by calling

Below is the class which seems to contain the problem:

package com.aquino.gridlayoutmanagerrecyclerview;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ActivityMain extends AppCompatActivity {

    RecyclerView rvMain;

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        rvMain = (RecyclerView) findViewById(;
        Bitmap[] logos = new Bitmap[12];
        logos[0] = BitmapFactory.decodeResource(getResources(), 
    logos[1] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_fb);
    logos[2] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_google);
    logos[3] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_insta);
    logos[4] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_linkedin);
    logos[5] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_microsoft);
    logos[6] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_myspace);
    logos[7] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_skype);
    logos[8] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_snapchat);
    logos[9] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_twitter);
    logos[10] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_viber);
    logos[11] = BitmapFactory.decodeResource(getResources(), R.drawable.logo_whatsapp);
    MyAdapter adapter = new MyAdapter(getResources().getStringArray(R.array.company_list), logos);
    rvMain.setLayoutManager(new GridLayoutManager(ActivityMain.this, 2));
}//end of onCreate()

private class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

    String[] companyList;
    Bitmap[] logoList;

    public MyAdapter(String[] companyList, Bitmap[] logoList) {
        this.companyList = companyList;
        this.logoList = logoList;

    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(v);
        return viewHolder;

    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.logo.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(this, AnotherActivity.class);

    public int getItemCount() {
        return companyList.length;

}//end of MyAdapter
private class MyViewHolder extends RecyclerView.ViewHolder{

    public ImageView logo;
    public TextView name;

    public MyViewHolder(View itemView) {
        logo = (ImageView)itemView.findViewById(;
        name = (TextView)itemView.findViewById(;
 }//end of MyViewHolder

I cannot figure out why it is not working to add intent inside private class MyAdapter.

Any help is welcome


As per your code, all are fine. but in the private adapter, you will not get the context of the class directly by “this”. so just replace code.

 Intent intent = new Intent(ActivityMain.this, AnotherActivity.class);

Leave a Reply

Your email address will not be published. Required fields are marked *