Monday, May 5, 2014

Android call urlConnectoin.getInputStream error java.io.EOFException



First of all, this code is read directly Baidu Baike my html page in Android using the program, and then to the analytical procedure, the problem now is that it has not yet begun to read, it has been given a!
As follows:

This is the error message:

07-05 23:31:36.827: W / System.err (2847): java.io.EOFException
07-05 23:31:36.835: W / System.err (2847): at java.util.zip.GZIPInputStream.readFully (GZIPInputStream.java: 214)
07-05 23:31:36.835: W / System.err (2847): at java.util.zip.GZIPInputStream . (GZIPInputStream.java: 81)
07-05 23:31:36.835: W / System.err (2847): at java.util.zip.GZIPInputStream . (GZIPInputStream.java: 64)
07-05 23:31:36.842: W / System.err (2847): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.initContentStream (HttpURLConnectionImpl.java: 539)
07-05 23:31:36.842: W / System.err (2847): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse (HttpURLConnectionImpl.java: 1046)
07-05 23:31:36.842: W / System.err (2847): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream (HttpURLConnectionImpl.java: 512)
07-05 23:31:36.842: W / System.err (2847): at com.avin.priney.utils.GBKGetter.getKnowledgeByWord (GBKGetter.java: 378)
07-05 23:31:36.842: W / System.err (2847): at com.avin.priney.android.AnswerStrategy.getFinalAnswer (AnswerStrategy.java: 265)
07-05 23:31:36.842: W / System.err (2847): at com.avin.priney.android.PrineyMainActivity.getResultTxtByQuestionTxt (PrineyMainActivity.java: 272)
07-05 23:31:36.850: W / System.err (2847): at com.avin.priney.android.PrineyMainActivity.onClick (PrineyMainActivity.java: 145)
07-05 23:31:36.850: W / System.err (2847): at android.view.View.performClick (View.java: 2485)
07-05 23:31:36.850: W / System.err (2847): at android.view.View $ PerformClick.run (View.java: 9090)
07-05 23:31:36.850: W / System.err (2847): at android.os.Handler.handleCallback (Handler.java: 587)
07-05 23:31:36.850: W / System.err (2847): at android.os.Handler.dispatchMessage (Handler.java: 92)
07-05 23:31:36.850: W / System.err (2847): at android.os.Looper.loop (Looper.java: 130)
07-05 23:31:36.858: W / System.err (2847): at android.app.ActivityThread.main (ActivityThread.java: 3859)
07-05 23:31:36.858: W / System.err (2847): at java.lang.reflect.Method.invokeNative (Native Method)
07-05 23:31:36.858: W / System.err (2847): at java.lang.reflect.Method.invoke (Method.java: 507)
07-05 23:31:36.858: W / System.err (2847): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 839)
07-05 23:31:36.858: W / System.err (2847): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 597)
07-05 23:31:36.858: W / System.err (2847): at dalvik.system.NativeStart.main (Native Method)


The following code segment posted the problem:

String webUrl = "http://baike.baidu.com/searchword/?word =" + nCode + "& pic = 1";
/ / Built-in Wikipedia page address
String contentUrl = "http://baike.baidu.com";
BufferedReader br = null;
String backLine = null;
URL url = null;
try {
url = new URL (webUrl);

Log.d ("Avin", "webUrl going open ...");

URLConnection conn = url.openConnection ();

Log.d ("Avin", "webUrl opened ...");

Log.d ("Avin", "the question is ->" + question);

/ / Display exception information is being given this line
br = new BufferedReader (new InputStreamReader (conn.getInputStream ()));


backLine = br.readLine ();

Log.d ("Avin", backLine);
int clmindex = 1;
while (backLine! = null) {
backLine = br.readLine ();
/ *
if (clmindex == 20) {
/ / Track to the target page where the line out of the loop
break;
}
* /
System.out.println (clmindex + "->" + backLine);
clmindex + +;
}
br.close ();


br = new BufferedReader (new InputStreamReader (conn.getInputStream ()));
This line error! Check the day's data, that is not progress,
This exception means that the file is read ends abnormally, the error status is returned, but the lines of code to see the error in this case it has not started to read the data, how it will end abnormally, baffled!

This code is placed JavaProject in on the right, on my cell phone will not work!


Desperation, hereby to other experts answer!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Attention, just have encountered this problem seems to be conn.getInputStream () wrong
Reply:
My program also seemed to buffer = new BufferedReader (new InputStreamReader (urlConn.getInputStream ()));, did not even run to catch a direct
Reply:
Yes, it is unusual when getInputStream! Previously used properly, after a few days on the bad, somehow, the feeling is not the problem of the program, the site seems to be what has changed, or is the web server directly shielding the tragedy! , Experts expect! And thank you for helping!
Reply:
I saw on stackoverflow, someone is
this solution forSystem.setProperty ("http.keepAlive", "false");

And we also verified, and really easy to use.
Reply:
Alas, I have encountered. . .
Reply:
I have encountered this problem, the landlord is how you solve?
Reply:
Experts expect to solve!
Reply:
Also encountered this problem, the landlord to solve it?
Reply:
Need to access the network configuration mainFest.xml file permissions

Reply:
Upstairs No, I have been added, or an error
Reply:
The landlord did not seek to get advice
Reply:
references, 4th Floor bonwei reply:
on stackoverflow I see someone is
this solution forSystem.setProperty ("http.keepAlive", "false");

And we also verified, and really easy to use.

Where does this add?
Reply:
The same problem, help ah
Reply:
Solve it?
keepAlive
Reply:
The same problem Yeah ~ ~ ~ I hope the experts rescue!
Reply:
I have encountered this problem, ask the landlord to solve it?
Reply:
So many people want to grab Baidu Baike page Yeah, I need this feature, but also encountered this problem, sometimes looks like a line, sometimes throwing the exception, strange
Reply:
There are so many people have to see this stuff and anguish.
I sent a link to it, according to this method can get rid
http://blog.sina.com.cn/s/blog_6c60678b0101e847.html
Reply:
In fact, the problem is that the thread
Reply:
Yet to find a solution
Reply:
Feeling is a web source more time will be ringing off the hook, if less then normal operation, do not know why

No comments:

Post a Comment