A new session could not be created. (Original error: 'java -version' failed. Error: Command failed:

Hi ,

I am a beginner in Mobile automation for Android and i am using Appium with TestNG framework. I am trying to launch camera/any native app of device.
Every time i run my code i get the error mentioned below-

A new session could not be created. (Original error: ‘java -version’ failed. Error: Command failed: ‘“C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe”’ is not recognized as an internal or external command…

I have tried to debug and ensured my appium server is running and only a single session exists. Also checked all environment variables like path, and Android_Home etc.Added all external jars properly. I am unable to understand why appium is trying to find something in the location mentioned above.

can anyone help please.

Did you set JAVA_HOME environment variable and add %JAVA_HOME%\bin to your path ? What happens when you type java -version in console manually ?

when i type Java -version in cmd, it displays me the java and JRE version.’

I have a variable named JAVA_HOME defined till the location of jdk, i have also added %JAVA_HOME%\bin path in my path variable.

Please post Appium logs. That way we can get a better idea of why you are getting this error.

Appium Logs

info: → POST /wd/hub/session {“desiredCapabilities”:{“newCommandTimeout”:120,“platformVersion”:“4.4.2”,“platformName”:“Android”,“deviceName”:“0123456789ABCDEF”,“appActivity”:“com.android.calculator2.Calculator”,“appPackage”:“com.android.calculator2”}}

info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] Didn’t get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 3a832e6a-65ec-4304-b26b-33d79d54e0a7
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
error: Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: Command failed: ‘“C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe”’ is not recognized as an internal or external command,
operable program or batch file.
java version “1.7.0_21”
Java™ SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot™ Client VM (build 23.21-b01, mixed mode, sharing)

info: [debug] Cleaning up appium session
info: [debug] Error: ‘java -version’ failed. Error: Command failed: ‘“C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe”’ is not recognized as an internal or external command,
operable program or batch file.
java version “1.7.0_21”
Java™ SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot™ Client VM (build 23.21-b01, mixed mode, sharing)

at [object Object].<anonymous> (C:\Program Files\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at ChildProcess.exithandler (child_process.js:641:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Socket.<anonymous> (child_process.js:956:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:465:12)

info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: ‘java -version’ failed. Error: Command failed: ‘"C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe"’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\njava version "1.7.0_21"\r\nJava™ SE Runtime Environment (build 1.7.0_21-b11)\r\nJava HotSpot™ Client VM (build 23.21-b01, mixed mode, sharing)\r\n)”,“origValue”:“‘java -version’ failed. Error: Command failed: ‘"C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe"’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\njava version "1.7.0_21"\r\nJava™ SE Runtime Environment (build 1.7.0_21-b11)\r\nJava HotSpot™ Client VM (build 23.21-b01, mixed mode, sharing)\r\n”},“sessionId”:null}
info: ← POST /wd/hub/session 500 406.972 ms - 902

Console logs
FAILED: testwhatsapp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: ‘java -version’ failed. Error: Command failed: ‘“C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe”’ is not recognized as an internal or external command,
operable program or batch file.
java version “1.7.0_21”
Java™ SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot™ Client VM (build 23.21-b01, mixed mode, sharing)
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.46 seconds
Build info: version: ‘2.43.1’, revision: ‘5163bce’, time: ‘2014-09-10 16:27:58’
System info: host: ‘Sumona’, ip: ‘172.17.0.154’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_21’
Driver info: io.appium.java_client.android.AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:22)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:202)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:50)
at Xolo.whatsapp.testwhatsapp(whatsapp.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@19ab9c5: 436 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6f513: 104 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@1927ba1: 36 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@167198e: 176 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@38c403: 43 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 42 ms

That’s very odd, since it seems Appium does get the java version properly (1.7.0_21), but still throws error at java -version.
Is there any chance you would have removed elements to path variable while adding ANDROID_HOME and JAVA_HOME ?
Try to look into that sbundattend.exe file itself.

I have not made any changes in path variable except android Home and Java home, moreover i checked the location which is present in error
C:\Users\Sumona Dasgupta\AppData\Roaming\Microsoft\Windows\IEUpdate\sbunattend.exe…

didnot find any “sbunattend.exe” file in this location

This problem seems unrelated to Appium. You should search for sbunattend.exe issues on the web. This file should probably be there, and it is a system file.

I have searched the web and found sbunattend.exe is a system file of windows and it contains step-by-step instructions that a computer follows to carry out a function.Without executable files like sbunattend.exe, you wouldn’t be able to use any programs on your PC. Its original location is C://Windows//System32 check out here

There must be some issues without your O/S so this error is coming. Appium server internally runs exe file while executing scripts…

At this point of time it will be difficult to say how to resolve this error… Can u try same appium configuration on different machine… if it’s working ?

Hi Amit and Alexis

thanks for the suggestion. I tried Appium in different system and it was working fine. hence i concluded te problem is related with my system but not the configurations i did. Its system admin permission related issue. I figured out and now everything is working fine…

thanks !

Hi Sumona

You can simply check "Override Existing session " in appium setting. and this will start working fine.

this happens when any of your test stops in between and your new test wants to start the new session of appium.

Hi All,
adding system32 location “%SystemRoot%\system32” as PATH variable under System variables will resolve the issue because basically appium might need something from system32 directory to interact with adb command during run time.

Hope this resolves the issue. :smile:

Regards
@Abdul_Sathar_Beigh

I got same kind of issue Not able to run Appium program {“message”:”A new session could not be created. (Original error: ‘java -version’ failed
My environment

Jdk jdk1.8.0_101 and JRE 1.8.0_101
Classpath set properly
Eclipse Kepler Service Release 2 with JDK1.8 support

I observed that Java comment gives Error to initialization of VM (java/lang/NoClassDefFoundError: java/lang/Object)

Solution:
Uninstall all Java packages of all versions.(Uninstalled JRE and JDK completely)
Download last packages Java SE or JRE for your 32 or 64 Windows and install it.
First install JRE and second is Java SE( Installed JRE 1.8 then Installed JDK 1.8)
Set Classpath check Java coomand works or not and its working also able to execute the Appium program