Intent fails because of Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()

后端 未结 2 528
轻奢々
轻奢々 2021-01-28 02:30

What I have: I have a RecyclerView with images of bars, coffee shops. etc

What I want: That when you click on one of these images I show you the info of the selected pla

相关标签:
2条回答
  • 2021-01-28 02:56

    I think you forget to pass context from activity !

    AdapterDatos adapter = new AdapterDatos(foodAndGo.this,listalugares);
    

    Receive context in Adapter :-

    public AdapterDatos(Context context , ArrayList<ClaseNueva> listalugares) {
            this.context = context;
            this.listalugares = listalugares;
        }
    

    I hope this help you!

    0 讨论(0)
  • 2021-01-28 03:11

    You need to fetch the context in adapter. I've another solution for. You can get context using the code below

    context = holder.foto.getContext();
    

    So, we will get context from foto component in adapter. Lets try!

    UPDATE

    You need to put that code in onBindViewHolder and above

    if (position == 0){
    
    0 讨论(0)
提交回复
热议问题