Hello team,i am facing issue when i run java application to connect with real android device please can you guide me how i resolve this issue

java.lang.reflect.InvocationTargetException
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 122 milliseconds
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘DESKTOP-854TOER’, ip: ‘192.168.10.10’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: driver.version: AppiumDriver
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘DESKTOP-854TOER’, ip: ‘192.168.10.10’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: driver.version: AppiumDriver
Unable to create a new remote session. Please check the server log for more details. Original error: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 122 milliseconds
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘DESKTOP-854TOER’, ip: ‘192.168.10.10’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: driver.version: AppiumDriver
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘DESKTOP-854TOER’, ip: ‘192.168.10.10’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: driver.version: AppiumDriver

at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:216)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:225)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:89)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:99)
at appiumtests.Calculator.OpenCalculator(Calculator.java:52)
at appiumtests.Calculator.main(Calculator.java:25)

Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:193)
… 13 more
Caused by: org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 122 milliseconds
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘DESKTOP-854TOER’, ip: ‘192.168.10.10’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.2’
Driver info: driver.version: AppiumDriver
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:1002)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
… 18 more

Could you post server log? Would be great as a git gist but if you can’t do that just post the text here (please not a screenshot).

Ok, I’m guessing that you don’t know how to get the server log, which is ok.

I do not see you starting the server in your code. Do you start the server manually? If so can you give the command you are using? If not, that may be your problem…

i strat the server by running command appium in terminal and it show me this first in logs .

[Appium] Welcome to Appium v2.11.3
[Appium] The autodetected Appium home path: C:\Users\abubakar
[Appium] Attempting to load driver uiautomator2…
[Appium] Requiring driver at C:\Users\abubakar\node_modules\appium-uiautomator2-driver\build\index.js
[Appium] AndroidUiautomator2Driver has been successfully loaded in 2.002s
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
http://192.168.10.10:4723/
http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] Available drivers:
[Appium] - [email protected] (automationName ‘UiAutomator2’)
[Appium] No plugins have been installed. Use the “appium plugin” command to install the one(s) you want to use.

…After running java application then it show this in logs…

[HTTP] Request idempotency key: f097a31f-2cea-470e-a547-2f2d912aeac0
[HTTP] → POST /wd/hub/session {“desiredCapabilities”:{“appActivity”:“io.selendroid.testapp.MainActivity”,“appPackage”:“io.selendroid.testapp”,“platformVersion”:“13”,“platformName”:“Android”,“udid”:“3c98ed44”,“deviceName”:“abu”},“capabilities”:{“firstMatch”:[{“appium:appActivity”:“io.selendroid.testapp.MainActivity”,“appium:appPackage”:“io.selendroid.testapp”,“appium:deviceName”:“abu”,“platformName”:“android”,“appium:platformVersion”:“13”,“appium:udid”:“3c98ed44”}]}}
[HTTP] No route found for /wd/hub/session
[HTTP] ← POST /wd/hub/session 404 12 ms - 211

Got it! Line 51 your code:
URL url = new URL("http://127.0.0.1:4723/wd/hub");
Can you change to:
URL url = new URL("http://127.0.0.1:4723/");

Or if you would prefer, start Appium server like this:
appium --base-path "/wd/hub"
Without changing your code.

You are currently running into this issue from Migration guide:

i used this command in the terminal to start server appium --base-path “/wd/hub” then run application and it show me same issue in logs…

[HTTP] → POST /wd/hub/session {“desiredCapabilities”:{“appActivity”:“io.selendroid.testapp.MainActivity”,“appPackage”:“io.selendroid.testapp”,“platformVersion”:“13”,“platformName”:“Android”,“udid”:“3c98ed44”,“deviceName”:“abu”},“capabilities”:{“firstMatch”:[{“appium:appActivity”:“io.selendroid.testapp.MainActivity”,“appium:appPackage”:“io.selendroid.testapp”,“appium:deviceName”:“abu”,“platformName”:“android”,“appium:platformVersion”:“13”,“appium:udid”:“3c98ed44”}]}}
[AppiumDriver@2a26] Calling AppiumDriver.createSession() with args: [{“appActivity”:“io.selendroid.testapp.MainActivity”,“appPackage”:“io.selendroid.testapp”,“platformVersion”:“13”,“platformName”:“Android”,“udid”:“3c98ed44”,“deviceName”:“abu”},null,{“firstMatch”:[{“appium:appActivity”:“io.selendroid.testapp.MainActivity”,“appium:appPackage”:“io.selendroid.testapp”,“appium:deviceName”:“abu”,“platformName”:“android”,“appium:platformVersion”:“13”,“appium:udid”:“3c98ed44”}]}]
[AppiumDriver@2a26] Event ‘newSessionRequested’ logged at 1723771865395 (06:31:05 GMT+0500 (Pakistan Standard Time))
[Appium] Could not parse W3C capabilities: ‘automationName’ can’t be blank
[AppiumDriver@2a26] Event ‘newSessionStarted’ logged at 1723771865403 (06:31:05 GMT+0500 (Pakistan Standard Time))
[AppiumDriver@2a26] Encountered internal error running command: InvalidArgumentError: ‘automationName’ can’t be blank
at processCapabilities (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\basedriver\capabilities.ts:338:13)
at parseCapsForInnerDriver (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\lib\utils.js:152:40)
at AppiumDriver.createSession (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\lib\appium.js:636:49)
at runCommandPromise (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\basedriver\driver.ts:115:20)
at AppiumDriver.executeCommand (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\basedriver\driver.ts:149:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at defaultBehavior (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\lib\appium.js:1119:16)
at AppiumDriver.executeWrappedCommand (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\lib\appium.js:1229:16)
at AppiumDriver.executeCommand (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\lib\appium.js:1135:17)
at asyncHandler (C:\Users\abubakar\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\protocol\protocol.js:387:19)
[HTTP] ← POST /wd/hub/session 400 74 ms - 1517

Not the same issue at all. Didn’t see this in first log. I recommend that you do a websearch on that error. In addition, here is a reference for Appium Capabilities:

This will explain the different Capability settings and the different values.

You may want to do a tutorial on Appium. Here is a good one: