Getting 'java -version' failed error while initiating session in window. Please help me to get out of this


Killed Node Server.
Node Server Process Ended
Starting Node Server
warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
info: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
info: Appium REST http interface listener started on
info: [debug] Non-default server args: {“app”:“D:\AUTOMATION\sample-code-master\sample-code-master\sample-code\apps\ContactManager\ContactManager.apk”,“address”:“”,“port”:4735,“logNoColors”:true,“avd”:“EM1”,“deviceName”:“Android Emulator”,“platformName”:“Android”,“platformVersion”:“19”,“automationName”:“Appium”}
info: Console LogLevel: debug
info: → POST /wd/hub/session {“desiredCapabilities”:{“platformName”:“Android”,“deviceName”:“Android Emulator”}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
error: Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: spawn ENOENT
info: [debug] Using local app from command line: D:\AUTOMATION\sample-code-master\sample-code-master\sample-code\apps\ContactManager\ContactManager.apk
info: [debug] Creating new appium session 8079f6ea-03f9-4efe-8cfe-c343cd803167
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: ‘java -version’ failed. Error: spawn ENOENT
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at exithandler (child_process.js:633:7)
at ChildProcess.errorhandler (child_process.js:649:5)
at ChildProcess.EventEmitter.emit (events.js:95:17)
at Process.ChildProcess._handle.onexit (child_process.js:795: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: spawn ENOENT)”,“origValue”:“‘java -version’ failed. Error: spawn ENOENT”},“sessionId”:null}
info: ← POST /wd/hub/session 500 15.168 ms - 208

Code:(java-client:3.1.0, app:1.4.0)
package testApiumPkg;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.util.concurrent.TimeUnit;

public class testApiumClass {
public static void main(String args) throws MalformedURLException {

	File classpathRoot = new File(System.getProperty("user.dir")); // path to Eclipse project

	File appDir = new File(classpathRoot, "/ContactManager"); // path to <project folder>/Contact Manager
	File app = new File(appDir, "ContactManager.apk");

// System.out.println(“Entered”);
DesiredCapabilities capabilities = new DesiredCapabilities();
// capabilities.setCapability(“appium-version”, “1.0”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“platformVersion”, “4.4”);
capabilities.setCapability(“deviceName”, “Android Emulator”);
capabilities.setCapability(“app”, app);
WebDriver wd = new RemoteWebDriver(new URL(“”), capabilities);
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

Apparently you don’t have java installed, or is missing from global path.

Try to reinstall java, or add it to global path. I don’t have windows, but here’s a link to fix this.