Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
00:28 11 Oct 2023

I am starting appium server without using cmd and desktop app and for that I have written code but after running that code I got this exception

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 
Host info: host: 'DESKTOP-SUFA48T', ip: '192.168.0.177'
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8.1'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:app=C:\Users\HP\Mobile Testing\MobileTestingAppium\src\test\java\resources\ApiDemos-debug.apk, appium:automationName=UiAutomator2, appium:deviceName=Pixel 2 API 28, platformName=ANDROID}], desiredCapabilities=Capabilities {app: C:\Users\HP\Mobile Testing\..., automationName: UiAutomator2, deviceName: Pixel 2 API 28, platformName: ANDROID}}]
Capabilities {}

I am using andriod emulator and running an app on it

Andriod Emulator

@Test
public void config() throws MalformedURLException {

    AppiumDriverLocalService service = new AppiumServiceBuilder()
            .withAppiumJS(
                    new File("C:\\Users\\HP\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))
            .withIPAddress("127.0.0.1").usingPort(4723).withTimeout(Duration.ofSeconds(300)).build();

    service.start();

    // Construct the complete URL with the custom base path
    URL link = new URL("http://127.0.0.1:4723/wd/hub");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel 2 API 28");
    capabilities.setCapability(MobileCapabilityType.APP,
            "C:\\Users\\HP\\Mobile Testing\\MobileTestingAppium\\src\\test\\java\\resources\\ApiDemos-debug.apk");
    capabilities.setCapability("automationName", "UiAutomator2"); // for Android

    AndroidDriver driver = new AndroidDriver(link, capabilities);

    driver.quit();

}

This is my code

Please Solve this issue Thanks in advance

java node.js appium appium-android