There is an error in the toast message (Android)

Asked 2 years ago, Updated 2 years ago, 22 views

public abstract class MypageActivity {

    private RecyclerView recyclerView;
    private RecyclerView.Adapter mAdapter;


    Map<String,Object> boxOfficeResult;
    private ArrayList<Map<String, Object>> jsonList;


    protected void onCreate(Bundle savedInstanceState) {}

    MySwipeHelper swipeHelper= new MySwipeHelper(MypageActivity.this,recyclerView,300) {
        @Override
        public void instantiatrMyButton(final RecyclerView.ViewHolder viewHolder, List<MyButton> buffer) {
            buffer.add(new MyButton(MypageActivity.this,
                    "Delete",
                    30,
                    R.drawable.ic_delete_white_24dp,
                    Color.parseColor("#FF3C30"),
                    new MyButtonClickListener() {
                        @Override
                        public void onClick(int pos) {
                            Toast.makeText(MypageActivity.this, "Delete click", Toast.LENGTH_SHORT).show();
                            Log.d("TAG",viewHolder.getAdapterPosition()+"");
                            jsonList.remove(viewHolder.getAdapterPosition())); // Delete that item
                            mAdapter.notifyItemRemoved(viewHolder.getAdapterPosition()); // Inform Adapter
                        }
                    }));
            buffer.add(new MyButton(MypageActivity.this,
                    "Update",
                    30,
                    R.drawable.ic_edit_edit_24dp,
                    Color.parseColor("#03DAC5"),
                    new MyButtonClickListener() {
                        @Override
                        public void onClick(int pos) {
                            Toast.makeText(MypageActivity.this, "edit click", Toast.LENGTH_SHORT).show();
                            //
                        }
                    }));
        }
    };// };// swipeHelper

}

Only toast messages fail.

Error Code)

error: incompatible types: MypageActivity cannot be converted to Context
    MySwipeHelper swipeHelper= new MySwipeHelper(MypageActivity.this,recyclerView,300) {

android

2022-09-20 22:15

2 Answers

It's the same as the error message.

MypageActivity cannot be converted to Context

If you look at the code now, MypageAcitivy is a class that doesn't inherit anything.

In other words, the name is Activity, not Activity.

That's why you get this error message.


2022-09-20 22:15

public abstract class MypageActivity {}

public abstract class MypageActivity extends AppCompatActivity {}

I want you to inherit it.


2022-09-20 22:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.