the code cant package com.example.uitest;

import androidx.appcompat.app.AppCompatActivity;

import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private int numCards = 8; // Number of unique cards
    private int[] cardValues = new int[numCards];
    private boolean[] cardVisible = new boolean[numCards];
    private ImageButton[] cardButtons = new ImageButton[numCards];

    private int cardsFlipped = 0;
    private ImageButton firstCard, secondCard;

    interface NonMatchingCardCallback {
        void onNonMatchingCards(ImageButton firstCard, ImageButton secondCard);
    }

    private NonMatchingCardCallback nonMatchingCardsCallback = new NonMatchingCardCallback() {
        @Override
        public void onNonMatchingCards(ImageButton firstCard, ImageButton secondCard) {
            // Implement your desired action for non-matching cards here
            // For example, flip the cards back
            firstCard.setVisibility(View.VISIBLE);
            secondCard.setVisibility(View.VISIBLE);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        assignCardValues();
        setCardButtons();
    }

    private void assignCardValues() {
        List<Integer> cardImages = new ArrayList<>(Arrays.asList(
                R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4,
                R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4));
        Collections.shuffle(cardImages);

        for (int i = 0; i < numCards; i++) {
            cardValues[i] = cardImages.get(i / 2);
            cardVisible[i] = true;
        }
    }

    private void setCardButtons() {
        int[] buttonIds = new int[numCards];
        for (int i = 0; i < numCards; i++) {
            buttonIds[i] = getResources().getIdentifier("card" + (i + 1), "id", getPackageName());
            cardButtons[i] = findViewById(buttonIds[i]);
            cardButtons[i].setTag(buttonIds[i]);
        }
    }

    public void onCardClick(View view) {
        ImageButton clickedCard = (ImageButton) view;

        if (clickedCard.getVisibility() != View.VISIBLE || cardsFlipped == 2) {
            return;
        }

        int clickedCardIndex = Arrays.asList(cardButtons).indexOf(clickedCard);
        if (!cardVisible[clickedCardIndex]) {
            return;
        }

        cardVisible[clickedCardIndex] = false;

        if (cardsFlipped == 0) {
            firstCard = clickedCard;
            cardsFlipped = 1;
        } else if (cardsFlipped == 1) {
            secondCard = clickedCard;
            cardsFlipped = 0;

            if (cardValues[clickedCardIndex] == cardValues[Arrays.asList(cardButtons).indexOf(firstCard)]) {
                firstCard.setVisibility(View.INVISIBLE);
                secondCard.setVisibility(View.INVISIBLE);
            } else {
                nonMatchingCardsCallback.onNonMatchingCards(firstCard, secondCard);
            }
        }
    }
} change the photo