Retrofit cannot connect to my local web server on port 3000 - android

My app that is using Retrofit (v1.6.1) to connect to REST web services cannot connect to my local web server (running on localhost), this is the error I am getting.
This is inside Nexus4 (v4.3) emulator, I am using Android Studio for development and I have added android.permission.INTERNET & android.permission.ACCESS_NETWORK_STATE permissions in manifest file.
The error says its waited for 15s but it does not, it errors out right away.
07-13 15:57:53.947 820-840/it.test.android.app.activity D/Retrofit﹕ ---> HTTP POST http://localhost:3000/app/auth/signin
07-13 15:57:54.132 820-840/it.test.android.app.activity D/Retrofit﹕ Content-Type: application/json; charset=UTF-8
07-13 15:57:54.132 820-840/it.test.android.app.activity D/Retrofit﹕ Content-Length: 44
07-13 15:57:54.157 820-840/it.test.android.app.activity D/Retrofit﹕ {"auth":{"email":"steve","password":"pass"}}
07-13 15:57:54.387 820-840/it.test.android.app.activity D/Retrofit﹕ ---> END HTTP (44-byte body)
07-13 15:57:54.657 820-840/it.test.android.app.activity D/Retrofit﹕ ---- ERROR http://localhost:3000/app/auth/signin
07-13 15:57:54.857 820-840/it.test.android.app.activity D/Retrofit﹕ java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 3000) after 15000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:223)
at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:842)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
at retrofit.client.UrlConnectionClient.prepareRequest(UrlConnectionClient.java:68)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:37)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:208)
            at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
            at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
            at java.net.Socket.connect(Socket.java:842)
            at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
            at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
            at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
            at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
            at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
            at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
            at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
            at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
            at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
            at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
            at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
            at retrofit.client.UrlConnectionClient.prepareRequest(UrlConnectionClient.java:68)
            at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:37)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
            at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at retrofit.Platform$Android$2$1.run(Platform.java:142)
            at java.lang.Thread.run(Thread.java:841)
07-13 15:57:54.857 820-840/it.test.android.app.activity D/Retrofit﹕ ---- END ERROR

On your phone connecting to localhost:3000 means "connect to port 3000 on local network interface" - which is local interface of the phone, not the port 3000 of the PC to which your phone is connected. There is nothing listening on port 3000 on the phone, so you get connection refused error.
Whould you're trying to do is (probably, hard to guess without more information) is to connect from the phone to port 3000 on you PC. So you should change the address you're connecting to from localhost to address of the PC. In case of emulator that would be 10.0.2.2 (which is localhost of the PC). See networking information for reference.

I solved the issue, need to use 10.0.2.2 instead of localhost to connect to my local server.
Found it here - http://developer.android.com/tools/devices/emulator.html#networkaddresses

Related

Crashlytics Initialization ConnectionException (EHOSTUNREACH)

I have the Crashlytics SDK installed on an Android app (through Fabric) and it was working perfectly before. All of a sudden, I'm getting ConnectionExceptions and Crashlytics cannot communicate with its remote server.
Fabric is instantiated at the end of onCreate in my Application class:
public void onCreate() {
super.onCreate();
...
Fabric.with(this, new Crashlytics());
}
Here is the stacktrace on app bootup. Any thoughts?
06-18 16:53:57.560 15388-15388/? I/Fabric﹕ Initializing Crashlytics 2.3.2.56
06-18 16:54:00.759 15388-15417/com.myapp E/Fabric﹕ Unknown error while loading Crashlytics settings. Crashes will be cached until settings can be retrieved.
io.fabric.sdk.android.services.network.HttpRequest$HttpRequestException: java.net.ConnectException: failed to connect to settings.crashlytics.com/54.83.37.39 (port 443) after 10000ms: isConnected failed: EHOSTUNREACH (No route to host)
at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1409)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:96)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:83)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:80)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:64)
at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:156)
at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:123)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.net.ConnectException: failed to connect to settings.crashlytics.com/54.83.37.39 (port 443) after 10000ms: isConnected failed: EHOSTUNREACH (No route to host)
at libcore.io.IoBridge.isConnected(IoBridge.java:238)
at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
at libcore.io.IoBridge.connect(IoBridge.java:122)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
at java.net.Socket.connect(Socket.java:882)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
at com.android.okhttp.Connection.connect(Connection.java:152)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1407)
            at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:96)
            at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:83)
            at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:80)
            at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:64)
            at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:156)
            at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:123)
            at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
            at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
            at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
            at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
            at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: isConnected failed: EHOSTUNREACH (No route to host)
at libcore.io.IoBridge.isConnected(IoBridge.java:223)
            at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
            at libcore.io.IoBridge.connect(IoBridge.java:122)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
            at java.net.Socket.connect(Socket.java:882)
            at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
            at com.android.okhttp.Connection.connect(Connection.java:152)
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
            at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
            at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
            at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1407)
            at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:96)
            at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:83)
            at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:80)
            at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:64)
            at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:156)
            at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:123)
            at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
            at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
            at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
            at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
            at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
I think I figured out the problem. The errors only seem to happen when I'm using my local Second Cup wifi network. When I use my home network, it works just fine.
There must be some sort of proxy issue going on here.

Permission denied - missing INTERNET permission?

I'm having problem with the internet permission. Yes I've looked around and I made sure the permission is outside the application tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.example.android.sunshine" >
<uses-permission android:name="android.permission.internet" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here's the logcat:
02-13 15:10:07.622 5879-5951/app.com.example.android.sunshine
E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: app.com.example.android.sunshine, PID: 5879
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:117)
at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:94)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
            at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
            at java.net.InetAddress.getAllByName(InetAddress.java:214)
            at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
            at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
            at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
            at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
            at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:117)
            at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:94)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
            at libcore.io.Posix.getaddrinfo(Native Method)
            at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
            at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
            at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
            at java.net.InetAddress.getAllByName(InetAddress.java:214)
            at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
            at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
            at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
            at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
            at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
            at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:117)
            at app.com.example.android.sunshine.ForecastFragment$FetchWeatherTask.doInBackground(ForecastFragment.java:94)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841) 02-13 15:15:07.659 5879-5951/app.com.example.android.sunshine I/Process﹕
Sending signal. PID: 5879 SIG: 9
Thanks for the help.
Please use:
<uses-permission android:name="android.permission.INTERNET" />
Please read here:
SecurityException: Permission denied (missing INTERNET permission?)
Depending on what you are doing you may need to add:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Official Docs: http://developer.android.com/reference/android/Manifest.permission.html
write it like this (with caps)
<uses-permission android:name="android.permission.INTERNET" />
you can also try adding this:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Mind the Capital-case. It is "INTERNET"
The permission in question is android.permission.INTERNET -- note that case matters.

Android first app Hello world logcat errors

I'm just using Ray wanderlich tutorial to create my first ever android app - a basic hello world. The app is successfully launched on the emulator and the text is displayed as expected. however i don;t like the errors in the logcat. Highly appreciate if someone helps me to identify why logcat behaving unexpectedly.
07-16 18:03:02.661 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:03:03.021 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:03:07.221 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
07-16 18:04:10.802 1353-1477/com.google.android.gms.wearable D/dalvikvm﹕ GC_FOR_ALLOC freed 500K, 21% free 2434K/3056K, paused 192ms, total 203ms
07-16 18:04:10.832 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Error writing to device
java.net.ConnectException: failed to connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:114)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.startupSocket(Socket.java:567)
at java.net.Socket.<init>(Socket.java:226)
at btx.run(SourceFile:130)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:101)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:567)
            at java.net.Socket.<init>(Socket.java:226)
            at btx.run(SourceFile:130)
07-16 18:04:11.072 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:04:11.232 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:04:15.312 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
07-16 18:05:18.643 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Error writing to device
java.net.ConnectException: failed to connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:114)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.startupSocket(Socket.java:567)
at java.net.Socket.<init>(Socket.java:226)
at btx.run(SourceFile:130)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:101)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:567)
            at java.net.Socket.<init>(Socket.java:226)
            at btx.run(SourceFile:130)
07-16 18:05:18.833 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:05:18.993 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:05:23.263 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
07-16 18:05:27.533 1247-1287/system_process D/ConnectivityService﹕ Sampling interval elapsed, updating statistics ..
07-16 18:05:27.753 1247-1287/system_process D/ConnectivityService﹕ Done.
07-16 18:05:27.763 1247-1287/system_process D/ConnectivityService﹕ Setting timer for 720seconds
07-16 18:06:10.304 1247-1247/system_process D/dalvikvm﹕ GC_FOR_ALLOC freed 415K, 11% free 4481K/5028K, paused 235ms, total 260ms
07-16 18:06:26.674 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Error writing to device
java.net.ConnectException: failed to connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:114)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.startupSocket(Socket.java:567)
at java.net.Socket.<init>(Socket.java:226)
at btx.run(SourceFile:130)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:101)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:567)
            at java.net.Socket.<init>(Socket.java:226)
            at btx.run(SourceFile:130)
07-16 18:06:26.824 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:06:27.064 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:06:31.314 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
07-16 18:07:34.675 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Error writing to device
java.net.ConnectException: failed to connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:114)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.startupSocket(Socket.java:567)
at java.net.Socket.<init>(Socket.java:226)
at btx.run(SourceFile:130)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:101)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:567)
            at java.net.Socket.<init>(Socket.java:226)
            at btx.run(SourceFile:130)
07-16 18:07:34.765 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:07:34.875 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:07:39.065 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
07-16 18:08:42.446 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Error writing to device
java.net.ConnectException: failed to connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.connect(IoBridge.java:114)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.startupSocket(Socket.java:567)
at java.net.Socket.<init>(Socket.java:226)
at btx.run(SourceFile:130)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.connect(Native Method)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:101)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:567)
            at java.net.Socket.<init>(Socket.java:226)
            at btx.run(SourceFile:130)
07-16 18:08:42.486 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Socket closed
07-16 18:08:42.576 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Waiting 4.0 seconds to retry connection
07-16 18:08:46.696 1353-1477/com.google.android.gms.wearable D/WearableConn﹕ Connecting via TCP to /10.0.2.2:5601
open a command prompt and type the command netstat and check whether port 5601 is open. if it is there then open another command prompt and type the following command
telnet localhost 5554
once connected
type
redir add tcp:5601:6000
and
quit
Check if it helps..

Google App Engine Connected Android Registration with Endpoints Server FAILED

I am trying to follow this guide to get an App Engine Connected Android Project working. However, when I try to run my Android application and register, the Registration with Google Cloud Messaging succeeds, but the Registration with Endpoints Server fails.
https://developers.google.com/eclipse/docs/endpoints-androidconnected-gae
I manually set the LOCAL_ANDROID_RUN = true in CloudEndpointUtils.java
Any ideas on how I can fix this issue? I have tried the suggestions in search results with no success.
Exception received when attempting to register with server at http://10.0.2.2:8888/_ah/api/
java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 8888) after 20000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:159)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
at java.net.Socket.connect(Socket.java:832)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:964)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.finalproject.GCMIntentService.onRegistered(GCMIntentService.java:163)
at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:251)
at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:153)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:61)
My screen on my phone looks similar to this:

Unable to download an image in android

I need to download twitter profile picture of mine and show it in an imageview on click of a button. Here is my code to download the profile picture of desired user.
public static InputStream getTwitterProfilePictureOfUser(String twitterId){
try {
return new DefaultHttpClient().execute(new HttpGet("http://api.twitter.com/1/users/profile_image?user_id="+twitterId+"&size=bigger")).getEntity().getContent();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Getting the following exceptions. Where i'am going wrong ?
javax.net.ssl.SSLException: Not trusted server certificate
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:92)
at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:174)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.tarams.android.giveblood.service.ServiceStub.getTwitterProfilePictureOfUser(ServiceStub.java:207)
at com.tarams.android.giveblood.activities.ProfileActivity.onCreate(ProfileActivity.java:128)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
at android.app.ActivityThread.access$2300(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:168)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:366)
... 24 more
Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:149)
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:202)
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:164)
You are attempting to connect to an HTTPS URL via and the SSL certificate provided by the site is not trusted by the devise you are running the code on. I suggest you read this question on setting up trust in the Apache HTTP Client

Categories

Resources