-2

I am new to Android Developing, am getting this error:

android.content.res.Resources$NotFoundException: Resource ID #0x7f070075

whenever I set the adapter to the Recycle View myrv.setAdapter(myAdapter); everything seems to be properly coded, I have checked many times my code and I am unable to find what is causing this.

Here is my code

package com.example.root.agenda;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    List<Contact> lstContact;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        lstContact = new ArrayList<>();


  lstContact.add(new Contact("Andrea", "5874-2563", "Normal", R.drawable.user_painted_black64));
    lstContact.add(new Contact("Daniela", "2013-2365", "Normal", R.drawable.user_black));
    lstContact.add(new Contact("Juan", "7584-2323", "Normal", R.drawable.user_painted64));
    lstContact.add(new Contact("Elena", "7541-2110", "Normal", R.drawable.user_painted_black64));
        lstContact.add(new Contact("Maria", "7504-2000", "Normal", R.drawable.user_painted_white64_1));
        lstContact.add(new Contact("Edgardo", "2048-2048", "Normal", R.drawable.user_painted_white64_1));
        lstContact.add(new Contact("Alfonso", "9514-3214", "Normal", R.drawable.user_painted_black64));
        lstContact.add(new Contact("Erick", "5412-3652", "Normal", R.drawable.user_painted_white64_1));
        lstContact.add(new Contact("Andrea", "5874-2563", "Normal", R.drawable.user_painted_black64));
        lstContact.add(new Contact("Daniela", "2013-2365", "Normal", R.drawable.user_black));

        RecyclerView myrv = (RecyclerView) findViewById(R.id.id_recyclerView);
        RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this, lstContact);
        myrv.setLayoutManager(new GridLayoutManager(this, 3));
        myrv.setAdapter(myAdapter);

     /*  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });*/
    }

    @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);
        return true;
    }

    @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) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

For the Recycler View

    package com.example.root.agenda;
    import android.content.Context;
    import android.content.Intent;
    import android.support.v7.widget.CardView;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.TextView;
    import java.util.List;
    public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

    private Context mContext;
    private List<Contact> mData;

    public RecyclerViewAdapter(Context mContext, List<Contact> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        view = mInflater.inflate(R.layout.cardview_contact_layout, parent, false);
        return new MyViewHolder(view);

    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.tv_contact_name.setText(mData.get(position).getNombre());
        holder.img_contact_thumbnail.setImageResource(mData.get(position).getThumbnail());
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //pasando datos al detalle de contacto
                Intent intent = new Intent(mContext, Contact_details_activity.class);
                intent.putExtra("Nombre", mData.get(position).getNombre());
                intent.putExtra("Numero de Telefono", mData.get(position).getTelefono());
                intent.putExtra("Thumbnail", mData.get(position).getThumbnail());
                mContext.startActivity(intent);

            }
        });

        //Click Listener
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tv_contact_name;
        ImageView img_contact_thumbnail;
        CardView cardView;

        public MyViewHolder(View itemView) {
            super(itemView);

            tv_contact_name = (TextView) itemView.findViewById(R.id.id_contact_name);
            img_contact_thumbnail = (ImageView) itemView.findViewById(R.id.id_contact_img);
            cardView = (CardView) itemView.findViewById(R.id.id_cardview);
        }
    }
}
Devil10
  • 1,853
  • 1
  • 18
  • 22
Edrumaz
  • 1
  • 1

3 Answers3

0

Try cleaning your project if that does not work then try putting only one thumbnail resource for all the list items which you are sure that exist in the project. If that works too, then we will try to find the issue in different way.

Fahed Yasin
  • 400
  • 2
  • 9
0

Search for this address (0x7f070075) in your R.java file.

You will find the ID which is causing the crash. This will help you fix your crash as well as save you from future hassles.

Geet Choubey
  • 1,069
  • 7
  • 23
-1

It seems that there is not error in code, it is better to post the logcat exception to understand find the issues

i have used the same code and it working fine , please find below code to compare

only things need to check it images are exist on the right path

// In on Create

    lstContact=new ArrayList<>();
    lstContact.add(new Contact("Andrea", "5874-2563", "Normal", R.drawable.user_painted_black64));
    lstContact.add(new Contact("Daniela", "2013-2365", "Normal", R.drawable.user_black));
    lstContact.add(new Contact("Juan", "7584-2323", "Normal", R.drawable.user_painted64));
    lstContact.add(new Contact("Elena", "7541-2110", "Normal", R.drawable.user_painted_black64));
    lstContact.add(new Contact("Maria", "7504-2000", "Normal", R.drawable.user_painted_white64_1));
    lstContact.add(new Contact("Edgardo", "2048-2048", "Normal", R.drawable.user_painted_white64_1));
    lstContact.add(new Contact("Alfonso", "9514-3214", "Normal", R.drawable.user_painted_black64));
    lstContact.add(new Contact("Erick", "5412-3652", "Normal", R.drawable.user_painted_white64_1));
    lstContact.add(new Contact("Andrea", "5874-2563", "Normal", R.drawable.user_painted_black64));
    lstContact.add(new Contact("Daniela", "2013-2365", "Normal", R.drawable.user_black));

    RecyclerView myrv = (RecyclerView) findViewById(R.id.id_recyclerView);
    RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this, lstContact);
    myrv.setLayoutManager(new GridLayoutManager(this, 3));
    myrv.setAdapter(myAdapter);

Revised Adapter class

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

    private Context mContext;
    private List<Contact> mData;

    public RecyclerViewAdapter(Context mContext, List<Contact> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        view = mInflater.inflate(R.layout.cardview_contact_layout, parent, false);
        return new MyViewHolder(view);

    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.tv_contact_name.setText(mData.get(position).getName());
        holder.img_contact_thumbnail.setImageResource(mData.get(position).getPhoto());
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
        pasando datos al detalle de contacto
                Intent intent = new Intent(mContext, Contact_details_activity.class);
                intent.putExtra("Nombre", mData.get(position).getNombre());
                intent.putExtra("Numero de Telefono", mData.get(position).getTelefono());
                intent.putExtra("Thumbnail", mData.get(position).getThumbnail());
                mContext.startActivity(intent);

            }
        });

        //Click Listener
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv_contact_name;
        ImageView img_contact_thumbnail;
        CardView cardView;

        public MyViewHolder(View itemView) {
            super(itemView);

            tv_contact_name = (TextView) itemView.findViewById(R.id.id_contact_name);
            img_contact_thumbnail = (ImageView) itemView.findViewById(R.id.id_contact_img);
            cardView = (CardView) itemView.findViewById(R.id.id_cardview);
        }
    }
}
Navin
  • 285
  • 1
  • 8