Help me to fix this Error

This is my code:
package amazon;

import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class StartApplication {

private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {

File classpathRoot = new File(System.getProperty(“user.dir”));
File appDir = new File(classpathRoot, “/Apps/Amazon/”);
File app = new File(appDir, “/Apps/Amazon/AmazonIndiaShopping_v6.3.0.3.apk”);

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(“deviceName”, “SpiceMI-520”);
capabilities.setCapability(“platformVersion”, “4.4.2”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“app”, app.getAbsolutePath());
capabilities.setCapability(“appPackage”, “Amazon/AmazonIndiaShopping_v6.3.0.3”);
capabilities.setCapability(“appActivity”, “com.amazon.mShop.home.HomeActivity”);

driver = new AndroidDriver(new URL(“http://127.0.0.1:4890/wd/hub”), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();

}

}

==================================================================
Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.48.2’, revision: ’41bccdd’, time: ‘2015-10-09 19:55:52’
System info: host: ‘LUASHU-PC’, ip: ‘100.84.49.136’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_65’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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:247)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:162)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:171)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
at amazon.StartApplication.main(StartApplication.java:29)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4890 [/127.0.0.1] failed: Connection refused: connect
Build info: version: ‘2.48.2’, revision: ’41bccdd’, time: ‘2015-10-09 19:55:52’
System info: host: ‘LUASHU-PC’, ip: ‘100.84.49.136’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_65’
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
… 11 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4890 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:67)
… 12 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 25 more

Train Asked on March 20, 2016 in Appium.
Add Comment
  • 3 Answer(s)

    Have you add emulator or device of Android OS?

    Reviewer Answered on March 21, 2016.
    Add Comment

    Make sure  your devices is running on  4890 port , it must be configured in APPIUM server ,

    1. check the device is active or not by ” adb device”   , you should able to see your emulator /Device in  command prompt
    2.try this commands

    adb kill-server

    adb start – server

    Train Answered on March 22, 2016.
    Add Comment

    Hi Praveen,

    Make sure device is active or not by  using ”adb device” in command prompt.
    Else
    By adding [%SystemRoot%\system32;%SystemRoot%] to the System PATH in environment variable, Advanced System settings (properties of My computer) .

    Default Answered on April 7, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.