Android应用程序 - java.net.SocketException异常:没有到主机的路由 [英] Android App - Java.Net.SocketException: No route to host
问题描述
我创建Android应用程序从媒体服务器流视频。我用我的频道列表视图和一个switch语句来控制视频。在switch语句中有JavaScript的code例如简单的作品:
webView.loadUrl(JavaScript的:无效(jwplayer()playlistItem(2)));
这工作不错,但随机抛出了这个错误不少。我找不到原因,我试着不等待视频加载并加载一个新的视频,有时它会导致它,有时它不,我只选择了4个视频切换前观看了5秒,这一段时间导致它,有时没有。我logcat中显示了这个:
03-20 14:19:29.710:D / dalvikvm(14679):GC_CONCURRENT释放426K,8%的免费7600K / 8199K,暂停3毫秒+ 3ms的
03-20 14:20:32.490:D / dalvikvm(14679):主题ID = 18:撤消后仍然暂停(SC = 1 DC = 1)
03-20 14:20:32.540:D / dalvikvm(14679):主题ID = 18:撤消后仍然暂停(SC = 1 DC = 1)
03-20 14:20:32.550:D / dalvikvm(14679):GC_CONCURRENT释放426K,8%的免费7599K / 8199K,暂停为4ms + 3ms的
03-20 14:20:37.220:W / System.err的(14679):java.net.SocketException异常:没有到主机的路由
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.platform.OSNetworkSystem.connect(本机方法)
03-20 14:20:37.220:W / System.err的(14679):在dalvik.system.BlockGuard $ WrappedNetworkSystem.connect(BlockGuard.java:369)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
03-20 14:20:37.220:W / System.err的(14679):在java.net.Socket.connect(Socket.java:901)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
03-20 14:20:37.220:W / System.err的(14679):在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):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnect离子(HttpURLConnectionImpl.java:292)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
03-20 14:20:37.220:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
03-20 14:20:37.230:W / System.err的(14679):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:624)
03-20 14:20:37.230:W / System.err的(14679):在dalvik.system.NativeStart.run(本机方法)
03-20 14:20:37.230:W / System.err的(14679):在dalvik.system.NativeStart.run(本机方法)
你的看法使javasctript?
webView.getSettings()setJavaScriptEnabled(真)。
此外,你应该考虑在JavaScript语句的末尾添加一个冒号。
webView.loadUrl(JavaScript的:无效(jwplayer()playlistItem(2)););
如果有什么做的,尝试捕捉异常,并尝试一定的次数,还有在网页视图的Android和httpclients一些不稳定性。
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.<init>(HttpConnection.java:75)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(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)
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.
这篇关于Android应用程序 - java.net.SocketException异常:没有到主机的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!