问题
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