It seems that the `mainNft` contract you're instantiating hasn't extended the `ERC721Enumerable` contract in its implementation.

It would work fine if the NFT contract being created **inherits/extends** the `ERC721Enumerable` contract like this:

```js
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import {ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract MyNFT is ERC721Enumerable {
    constructor(string memory name, string memory symbol)
        ERC721(name, symbol)
    {}

    function mint(address to, uint256 tokenId) public {
        _mint(to, tokenId);
    }
}

contract MyNFTCount {
    IERC721Enumerable public mainNft;

    constructor(address myNFTAddress) {
        mainNft = IERC721Enumerable(myNFTAddress);
    }

    function viewOwnerNFTBalance(address _owner)
        public
        view
        returns (uint256 balanceOfOwner)
    {
        return mainNft.balanceOf(_owner);
    }

    function getTokenIdOfOwnerByIndex(address _owner, uint256 index)
        public
        view
        returns (uint256)
    {
        return mainNft.tokenOfOwnerByIndex(_owner, index);
    }

    function getTokenIdsOfOwner(address _owner)
        public
        view
        returns (uint256[] memory tokensOfOwner)
    {
        uint256 _len = mainNft.balanceOf(_owner);
        uint256[] memory _tokensOfOwner = new uint256[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _tokensOfOwner[i] = mainNft.tokenOfOwnerByIndex(_owner, i);
        }
        return _tokensOfOwner;
    }
}
```