Home > Back-end >  Cannot Resolve Constructor when intends to redirect an Activity
Cannot Resolve Constructor when intends to redirect an Activity

Time:01-24

Hi guys ive been wanting to open to another activity when any of the item within the recycler view has been clicked or pressed. And when i declaring the intent like this it gave me this error

Cannot resolve constructor 'Intent(com.example.fyptest1.RoomAdapter, java.lang.Class<com.example.fyptest1.staffSpecificRoomActivity>)'

This here is the code

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewer) {
            Intent intent = new Intent(RoomAdapter.this,staffSpecificRoomActivity.class);
        }
    });

And when i change to "this" it gave me error as well, my program is not using fragment so getApplication context is not usable right?

Cannot resolve constructor 'Intent(anonymous android.view.View.OnClickListener, java.lang.Class<com.example.fyptest1.staffSpecificRoomActivity>)'

Intent intent = new Intent(this,staffSpecificRoomActivity.class);

CodePudding user response:

Just add this "viewer" to the line of code and ure good to go

Intent intent = new Intent(viewer.getContext(),staffSpecificRoomActivity.class);
  •  Tags:  
  • Related