Getting Error pageFactory

i’m Getting error “java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field”

Error detail

java.lang.IllegalArgumentException: Can not set io.appium.java_client.android.AndroidElement field test.pageObjectLogin.insertUserID to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) at java.lang.reflect.Field.set(Field.java:764) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:117) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105) at test.BasePage.(BasePage.java:25) at test.pageObjectLogin.(pageObjectLogin.java:13) at test.TestTODOLogin.testLogin(TestTODOLogin.java:12) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.testng.TestRunner.privateRun(TestRunner.java:766) at org.testng.TestRunner.run(TestRunner.java:587) at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) at org.testng.SuiteRunner.access$000(SuiteRunner.java:28) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:425) at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

using constructor like below

BasePage.java

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class BasePage {

    public static AppiumDriver<MobileElement> driver;

    public BasePage(AppiumDriver<MobileElement> driver){
        this.driver = driver;;
        PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(10)), this);
    }

    public void waitForVisibility(AndroidElement e){
        WebDriverWait wait = new WebDriverWait(driver, TestUtils.WAIT);
        wait.until(ExpectedConditions.visibilityOf(e));
    }
    public String getAttribute(AndroidElement e, String attribute){
        waitForVisibility(e);
        return e.getAttribute(attribute);
    }
    public void sendKeys(AndroidElement e, String txt){
        waitForVisibility(e);
        e.sendKeys(txt);
    }
}

try to remove “<MobileElement>” and static better avoid.

public static AppiumDriver<MobileElement> driver;

->

final private AppiumDriver driver;