java.net.SocketException: Connection reset by peer - android

07-28 12:41:40.953: W/System.err(3386): java.net.SocketException: Connection reset by peer
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.platform.OSNetworkSystem.read(Native Method)
07-28 12:41:40.953: W/System.err(3386): at dalvik.system.BlockGuard$WrappedNetworkSystem.read(BlockGuard.java:273)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:458)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
07-28 12:41:40.953: W/System.err(3386): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:166)
07-28 12:41:40.953: W/System.err(3386): at java.io.BufferedInputStream.read(BufferedInputStream.java:225)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readLine(HttpURLConnectionImpl.java:660)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readResponseHeaders(HttpURLConnectionImpl.java:690)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1040)
07-28 12:41:40.953: W/System.err(3386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
07-28 12:41:40.953: W/System.err(3386): at com.android.epaisa.Info.submitInfo(Info.java:168)
07-28 12:41:40.953: W/System.err(3386): at com.android.epaisa.Info.onClick(Info.java:62)
07-28 12:41:40.953: W/System.err(3386): at android.view.View.performClick(View.java:2485)
07-28 12:41:40.953: W/System.err(3386): at android.view.View$PerformClick.run(View.java:9080)
07-28 12:41:40.953: W/System.err(3386): at android.os.Handler.handleCallback(Handler.java:587)
07-28 12:41:40.953: W/System.err(3386): at android.os.Handler.dispatchMessage(Handler.java:92)
07-28 12:41:40.953: W/System.err(3386): at android.os.Looper.loop(Looper.java:130)
07-28 12:41:40.953: W/System.err(3386): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-28 12:41:40.953: W/System.err(3386): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 12:41:40.953: W/System.err(3386): at java.lang.reflect.Method.invoke(Method.java:507)
07-28 12:41:40.953: W/System.err(3386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-28 12:41:40.960: W/System.err(3386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-28 12:41:40.960: W/System.err(3386): at dalvik.system.NativeStart.main(Native Method)
Line where error is occurring is
InputStream is = conn.getInputStream();
The connection is valid stream
Please help me in solving the issue . I am getting this error while trying to access a JSON object. upon manually checking the URL the result is as expected. I am trying to send an jpg image file compressing it converting it into byte array and then sending over the internet.
Thanks and Regards,

Guys the error was occurring because of timeout due to slow response in the internet connection and thus the connection was getting reset as per the coding at the backend.

Related

Android LogCat Error Videos and Images

i show on my tablelayout two videos and two images. For the videos i use the VideoView and for the images i use Picasso. All code is writed with Xamarin Android.
After any hours i have this error in logcat, but i don't understand the problem.
Can someone help me ? Sorry for my english.
07-28 13:47:35.090: E/Surface(2313): queueBuffer: error queuing buffer to SurfaceTexture, -19
07-28 13:47:35.090: E/Surface(2313): queueBuffer (handle=0x6a578a80) failed (No such device)
07-28 13:47:35.110: E/ViewRootImpl(2313): Could not unlock surface
07-28 13:47:35.110: E/ViewRootImpl(2313): java.lang.IllegalArgumentException
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Surface.nativeUnlockCanvasAndPost(Native Method)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Surface.unlockCanvasAndPost(Surface.java:285)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2584)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2437)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2281)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1892)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1005)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5750)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Choreographer.doFrame(Choreographer.java:544)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.os.Handler.handleCallback(Handler.java:733)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.os.Handler.dispatchMessage(Handler.java:95)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.os.Looper.loop(Looper.java:136)
07-28 13:47:35.110: E/ViewRootImpl(2313): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-28 13:47:35.110: E/ViewRootImpl(2313): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 13:47:35.110: E/ViewRootImpl(2313): at java.lang.reflect.Method.invoke(Method.java:515)
07-28 13:47:35.110: E/ViewRootImpl(2313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-28 13:47:35.110: E/ViewRootImpl(2313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-28 13:47:35.110: E/ViewRootImpl(2313): at dalvik.system.NativeStart.main(Native Method)
07-28 13:47:35.130: E/ViewRootImpl(2313): drawSoftware() getRotation() error~~~#!
07-28 13:47:37.220: W/IMediaDeathNotifier(2313): media server died
07-28 13:47:37.220: E/MediaPlayer(2313): error (100, 0)
07-28 13:47:37.220: W/AudioSystem(2313): AudioFlinger server died!
07-28 13:47:37.220: E/MediaPlayer(2313): error (100, 0)
07-28 13:47:37.220: E/MediaPlayer(2313): Error (100,0)
07-28 13:47:37.220: D/VideoView(2313): Error: 100,0
07-28 13:47:37.300: D/AndroidRuntime(2313): Shutting down VM
07-28 13:47:37.300: W/dalvikvm(2313): threadid=1: thread exiting with uncaught exception (group=0x418e22a0)
07-28 13:47:37.330: E/AndroidRuntime(2313): FATAL EXCEPTION: main
07-28 13:47:37.330: E/AndroidRuntime(2313): Process: com.XXX.XXX, PID: 2313
07-28 13:47:37.330: E/AndroidRuntime(2313): java.lang.RuntimeException: Adding window failed
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.view.ViewRootImpl.setView(ViewRootImpl.java:516)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.app.Dialog.show(Dialog.java:286)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.widget.VideoView$5.onError(VideoView.java:515)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2248)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.os.Handler.dispatchMessage(Handler.java:102)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.os.Looper.loop(Looper.java:136)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-28 13:47:37.330: E/AndroidRuntime(2313): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 13:47:37.330: E/AndroidRuntime(2313): at java.lang.reflect.Method.invoke(Method.java:515)
07-28 13:47:37.330: E/AndroidRuntime(2313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-28 13:47:37.330: E/AndroidRuntime(2313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-28 13:47:37.330: E/AndroidRuntime(2313): at dalvik.system.NativeStart.main(Native Method)
07-28 13:47:37.330: E/AndroidRuntime(2313): Caused by: android.os.DeadObjectException
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.os.BinderProxy.transact(Native Method)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:721)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.view.ViewRootImpl.setView(ViewRootImpl.java:505)
07-28 13:47:37.330: E/AndroidRuntime(2313): ... 14 more
07-28 13:47:37.330: I/Process(2313): Sending signal. PID: 2313 SIG: 9
07-28 13:47:37.330: E/AndroidRuntime(2313): Error reporting crash
07-28 13:47:37.330: E/AndroidRuntime(2313): android.os.DeadObjectException
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.os.BinderProxy.transact(Native Method)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:3703)
07-28 13:47:37.330: E/AndroidRuntime(2313): at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:84)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.runtime.UncaughtExceptionHandler.n_uncaughtException(Native Method)
07-28 13:47:37.330: E/AndroidRuntime(2313): at android.runtime.UncaughtExceptionHandler.uncaughtException(UncaughtExceptionHandler.java:37)
07-28 13:47:37.330: E/AndroidRuntime(2313): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
07-28 13:47:37.330: E/AndroidRuntime(2313): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
07-28 13:47:37.330: E/AndroidRuntime(2313): at dalvik.system.NativeStart.main(Native Method)

Cocos2d-x game built with Android API 21 is not working on lower API versions

I have built cocos2d-x game using Android API 21 but it is not working on lower API version, game crashes on startup. These are the logs:
07-28 22:09:47.358: E/dalvikvm(6483): dlopen("/data/app-lib/com.pld.readingrace1a-1/libcocos2dcpp.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "rand" referenced by "libcocos2dcpp.so"...
07-28 22:09:47.366: E/AndroidRuntime(6483): FATAL EXCEPTION: main
07-28 22:09:47.366: E/AndroidRuntime(6483): java.lang.ExceptionInInitializerError
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.Class.newInstanceImpl(Native Method)
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.Class.newInstance(Class.java:1319)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.os.Looper.loop(Looper.java:137)
07-28 22:09:47.366: E/AndroidRuntime(6483): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 22:09:47.366: E/AndroidRuntime(6483): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-28 22:09:47.366: E/AndroidRuntime(6483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.Runtime.loadLibrary(Runtime.java:371)
07-28 22:09:47.366: E/AndroidRuntime(6483): at java.lang.System.loadLibrary(System.java:535)
07-28 22:09:47.366: E/AndroidRuntime(6483): at org.cocos2dx.cpp.AppActivity.<clinit>(AppActivity.java:272)
I have searched and found some answers on stack overflow like
this one
but I want to build my game on API 21 because I am using some new features and I want it to work on older API versions. Can someone help in this regard. Thanks.
Make sure you set your TARGET SDK to a lower version. You should still be able to access most of the API 21 features.

Android Concurrency Collections

i am working on an app that has running many async tasks that bring data from server and approx 20 async task are running at a time and there are some threads which validate the data simulatenously.
I have made data models which update my Collections in which data is being stored.
The structure to save data resides on Hashmap that contains an arraylist
So my Question is
Is Android Context ThreadSafe
Are Hashmaps in android ThreadSafe
I am using a Handler to Communicate messages so in this case Handler has a Message Queue is that threadsafe.
because sometimes one out of 10 times my app crashes giving
this is just one logcat in this case it happens while iterating, there are cases in which one task is reading hashmap and other is updating it this is the case in which mostly app crashes.
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): FATAL EXCEPTION: main
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): java.util.ConcurrentModificationException
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.Juggle2.Panel.onTouchEvent(Panel.java:823)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.view.View.dispatchTouchEvent(View.java:3766)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1767)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1119)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1751)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.os.Looper.loop(Looper.java:123)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at java.lang.reflect.Method.invoke(Method.java:521)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
07-28 15:36:59.815: ERROR/AndroidRuntime(4026): at dalvik.system.NativeStart.main(Native Method)
which is clear indication that when async tasks and threads are trying to update arrayList / hashmaps they give this concurrency exception.
Array Lists and Hashmaps are not thread safe. I would suggest using mutex / synchronized blocks to ensure that only one thread is reading / writing to your collections at a time. Here is a small example to get you started.
public class SomeClass {
private final Object mutex = new Object();
public void someMethodThatNeedsAMutex() {
synchronized(mutex) {
//here you hold the mutex
}
}
}

Retrofit cannot connect to my local web server on port 3000

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

Unable to map a ListView with ArrayList

I am using Arraylist with definition
ArrayList<HashMap<String, String>> placesListItems = new ArrayList<HashMap<String,String>>();
Using following code to populate the Arraylist
for (Place p : placelist.getPlaces()) {
HashMap<String, String> map = new HashMap<String, String>();
// Place reference won't display in listview - it will be hidden
// Place reference is used to get "place full details"
map.put(KEY_REFERENCE, p.getReference());
// Place name
map.put(KEY_NAME, p.getName());
// adding HashMap to ArrayList
placesListItems.add(map);
}
and following code to bind it to a listview
ListAdapter adapter = new SimpleAdapter(this, placesListItems,
R.layout.list_item,
new String[] { KEY_REFERENCE, KEY_NAME}, new int[] {
R.id.reference, R.id.name });
lv.setAdapter(adapter);
the problem is, My ListView stays blank and stops unexpectedly after a few moments.
I have checked using debugger that placelistitems was correctly built.
Any help would be highly appreciated.
Thanks!
EDIT:
It is something to do with values recieved but I am not sure what. I am using google Place's JSON response to feed data to this arraylist.
here is my logcat:
07-28 21:18:33.709: W/System.err(8176): org.json.JSONException: No value for rating
07-28 21:18:33.709: W/System.err(8176): at org.json.JSONObject.get(JSONObject.java:354)
07-28 21:18:33.719: W/System.err(8176): at org.json.JSONObject.getDouble(JSONObject.java:409)
07-28 21:18:33.719: W/System.err(8176): at org.gmarz.googleplaces.models.Place.<init>(Place.java:36)
07-28 21:18:33.719: W/System.err(8176): at org.gmarz.googleplaces.models.PlacesResult.<init>(PlacesResult.java:21)
07-28 21:18:33.719: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:94)
07-28 21:18:33.719: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:53)
07-28 21:18:33.729: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:66)
07-28 21:18:33.729: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:71)
07-28 21:18:33.729: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:26)
07-28 21:18:33.729: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:33.729: W/System.err(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:33.729: W/System.err(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:33.739: W/System.err(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:33.739: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:33.739: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:33.739: W/System.err(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:33.749: W/System.err(8176): org.json.JSONException: No value for rating
07-28 21:18:33.759: W/System.err(8176): at org.json.JSONObject.get(JSONObject.java:354)
07-28 21:18:33.759: W/System.err(8176): at org.json.JSONObject.getDouble(JSONObject.java:409)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.models.Place.<init>(Place.java:36)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.models.PlacesResult.<init>(PlacesResult.java:21)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:94)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:53)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:66)
07-28 21:18:33.769: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:71)
07-28 21:18:33.769: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:26)
07-28 21:18:33.779: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:33.779: W/System.err(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:33.779: W/System.err(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:33.779: W/System.err(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:33.779: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:33.789: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:33.789: W/System.err(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:33.819: W/System.err(8176): org.json.JSONException: No value for rating
07-28 21:18:33.859: W/System.err(8176): at org.json.JSONObject.get(JSONObject.java:354)
07-28 21:18:33.989: W/System.err(8176): at org.json.JSONObject.getDouble(JSONObject.java:409)
07-28 21:18:33.989: W/System.err(8176): at org.gmarz.googleplaces.models.Place.<init>(Place.java:36)
07-28 21:18:33.989: W/System.err(8176): at org.gmarz.googleplaces.models.PlacesResult.<init>(PlacesResult.java:21)
07-28 21:18:34.009: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:94)
07-28 21:18:34.019: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:53)
07-28 21:18:34.039: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:66)
07-28 21:18:34.039: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:71)
07-28 21:18:34.039: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:26)
07-28 21:18:34.039: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:34.049: W/System.err(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:34.049: W/System.err(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:34.049: W/System.err(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:34.049: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:34.049: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:34.049: W/System.err(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:34.049: W/System.err(8176): org.json.JSONException: No value for rating
07-28 21:18:34.069: W/System.err(8176): at org.json.JSONObject.get(JSONObject.java:354)
07-28 21:18:34.069: W/System.err(8176): at org.json.JSONObject.getDouble(JSONObject.java:409)
07-28 21:18:34.069: W/System.err(8176): at org.gmarz.googleplaces.models.Place.<init>(Place.java:36)
07-28 21:18:34.069: W/System.err(8176): at org.gmarz.googleplaces.models.PlacesResult.<init>(PlacesResult.java:21)
07-28 21:18:34.069: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:94)
07-28 21:18:34.069: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:53)
07-28 21:18:34.069: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:66)
07-28 21:18:34.079: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:71)
07-28 21:18:34.079: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:26)
07-28 21:18:34.079: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:34.079: W/System.err(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:34.079: W/System.err(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:34.079: W/System.err(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:34.079: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:34.089: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:34.089: W/System.err(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:34.089: W/System.err(8176): org.json.JSONException: No value for rating
07-28 21:18:34.099: W/System.err(8176): at org.json.JSONObject.get(JSONObject.java:354)
07-28 21:18:34.099: W/System.err(8176): at org.json.JSONObject.getDouble(JSONObject.java:409)
07-28 21:18:34.099: W/System.err(8176): at org.gmarz.googleplaces.models.Place.<init>(Place.java:36)
07-28 21:18:34.099: W/System.err(8176): at org.gmarz.googleplaces.models.PlacesResult.<init>(PlacesResult.java:21)
07-28 21:18:34.099: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:94)
07-28 21:18:34.109: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:53)
07-28 21:18:34.109: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:66)
07-28 21:18:34.109: W/System.err(8176): at org.gmarz.googleplaces.GooglePlaces.getPlaces(GooglePlaces.java:71)
07-28 21:18:34.119: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:26)
07-28 21:18:34.119: W/System.err(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:34.119: W/System.err(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:34.119: W/System.err(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:34.119: W/System.err(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:34.119: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:34.119: W/System.err(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:34.119: W/System.err(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:34.159: W/dalvikvm(8176): threadid=9: thread exiting with uncaught exception (group=0x40018578)
07-28 21:18:34.329: E/AndroidRuntime(8176): FATAL EXCEPTION: AsyncTask #1
07-28 21:18:34.329: E/AndroidRuntime(8176): java.lang.RuntimeException: An error occured while executing doInBackground()
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.lang.Thread.run(Thread.java:1019)
07-28 21:18:34.329: E/AndroidRuntime(8176): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewRoot.checkThread(ViewRoot.java:3020)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewRoot.focusableViewAvailable(ViewRoot.java:1718)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:452)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.View.setFlags(View.java:4614)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.view.View.setFocusableInTouchMode(View.java:3190)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.widget.AdapterView.checkFocus(AdapterView.java:694)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.widget.ListView.setAdapter(ListView.java:503)
07-28 21:18:34.329: E/AndroidRuntime(8176): at com.example.testlibrary.MainActivity.processFinish(MainActivity.java:66)
07-28 21:18:34.329: E/AndroidRuntime(8176): at com.example.testlibrary.Async.doInBackground(Async.java:28)
07-28 21:18:34.329: E/AndroidRuntime(8176): at com.example.testlibrary.Async.doInBackground(Async.java:1)
07-28 21:18:34.329: E/AndroidRuntime(8176): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-28 21:18:34.329: E/AndroidRuntime(8176): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-28 21:18:34.329: E/AndroidRuntime(8176): ... 4 more
Another Edit:
here is my list XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="#+id/reference"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10sp"
android:textStyle="bold"
android:textSize="16sp"/>
<ListView
android:id="#+id/lvPlaces"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="26dp" >
</ListView>
</LinearLayout>
ListAdapter adapter = new SimpleAdapter(filename.this, placesListItems,
R.layout.list_item,
new String[] { KEY_REFERENCE, KEY_NAME}, new int[] {
R.id.reference, R.id.name });
// lv.setAdapter(adapter);
setListAdapter(adapter);

Categories

Resources