android java.net,Android App - Java.Net.SocketException: No route to host

问题

I'm creating an android app which streams video from a media server. I'm using a list view for my channels and a switch statement to control the videos. In the switch statement there are simple pieces of javascript code e.g.:

webView.loadUrl("javascript:void(jwplayer().playlistItem(2))");

This works okay but randomly throws up this error quite a lot. I can't find the cause, I've tried not waiting for the video to load and load a new video, sometimes it causes it, sometimes it doesnt, I've selected only 4 videos and watched 5 seconds before changing, this sometime causes it, sometimes doesn't. My logcat shows this:

03-20 14:19:29.710: D/dalvikvm(14679): GC_CONCURRENT freed 426K, 8% free 7600K/8199K, paused 3ms+3ms

03-20 14:20:32.490: D/dalvikvm(14679): threadid=18: still suspended after undo (sc=1 dc=1)

03-20 14:20:32.540: D/dalvikvm(14679): threadid=18: still suspended after undo (sc=1 dc=1)

03-20 14:20:32.550: D/dalvikvm(14679): GC_CONCURRENT freed 426K, 8% free 7599K/8199K, paused 4ms+3ms

03-20 14:20:37.220: W/System.err(14679): java.net.SocketException: No route to host

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)

03-20 14:20:37.220: W/System.err(14679): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:369)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)

03-20 14:20:37.220: W/System.err(14679): at java.net.Socket.connect(Socket.java:901)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:75)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:48)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnect ion(HttpURLConnectionImpl.java:292)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)

03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)

03-20 14:20:37.230: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:624)

03-20 14:20:37.230: W/System.err(14679): at dalvik.system.NativeStart.run(Native Method)

03-20 14:20:37.230: W/System.err(14679): at dalvik.system.NativeStart.run(Native Method)

回答1:

Did you enable javasctript on the view ?

webView.getSettings().setJavaScriptEnabled(true);

also, you should consider adding a colon at the end of the javascript statement.

webView.loadUrl("javascript:void(jwplayer().playlistItem(2));");

If there is nothing to do, try catching the exception and, try a certain number of times, there are some instabilities in webviews and httpclients in android.

来源:https://stackoverflow.com/questions/9788163/android-app-java-net-socketexception-no-route-to-host

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值