First of all, this code is read directly on the Android program using Baidu Encyclopedia of html page, and then to analyze the program, the problem now is that it has not yet begun reading, had already given up!
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.
07-05 23:31:36.835: W / System.err (2847): at java.util.zip.GZIPInputStream.
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 snippet posted out problems:
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);
/ / exception information is displayed in this line error
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) {
/ / trace the line to the target page, out of the loop
break;
}
* /
System.out.println (clmindex + "->" + backLine);
clmindex + +;
}
br.close ();
br = new BufferedReader (new InputStreamReader (conn.getInputStream ())); This line error! Checked the data for one day, that is not progress,
This exception means that the read file ends abnormally, the return error status, but look at the line of code being given at this time it has not yet started to read the data, how would abend it, baffled!
this code in JavaProject in on the right, to my cell phone will not work! <>
desperation, hereby to other experts to answer!
------ Solution ---------------------------------------- ----
attention, just have encountered this problem, it seems conn.getInputStream () wrong
------ Solution --------------- -----------------------------
my program also seemed to buffer = new BufferedReader (new InputStreamReader ( urlConn.getInputStream ()));, did not even run directly to the catch of the
------ Solution --------------------- -----------------------
stackoverflow I saw, it was like this solution
System.setProperty ("http.keepAlive", "false");
And we also verified, and really easy to use.
------ Solution ---------------------------------------- ----
I also encountered alas. . .
------ For reference only -------------------------------------- -
Yes, that getInputStream time unusually! Previously used properly, a few days on the bad, somehow, the feeling is not the question of procedure, the site seems to be what has changed, or is the web server directly shielding, the tragedy! , Experts expect! Also like to thank everyone for helping!
------ For reference only -------------------------------------- -
I have encountered this problem, the landlord you how to solve?
------ For reference only -------------------------------------- -
expect experts to solve!
------ For reference only -------------------------------------- -
also encountered this problem, the landlord to solve it?
------ For reference only -------------------------------------- -
need to mainFest.xml file to configure access to the network
------ For reference only ------------- --------------------------
Upstairs No, I have been added, or error
---- - For reference only ---------------------------------------
get the landlord yet seek advice
------ For reference only -------------------------------- -------
Where does this add?
------ For reference only -------------------------------------- -
same problem, help
------ For reference only ----------------------------- ----------
solve it?
keepAlive
------ For reference only --------------------------------- ------
same problem ah ~ ~ ~ I hope you save them!
------ For reference only ------------------ ---------------------
I have encountered this problem, ask the landlord to solve it?
------ For reference only -------------------------------------- -
so many pages to crawl Baidu Encyclopedia Yeah, I also need this feature, but also encountered this problem, looks like is sometimes OK, sometimes throwing the exception, strange
----- - For reference only ---------------------------------------
see so people have to this stuff and anguish.
I send a link to it, according to this method can get rid of
http://blog.sina.com.cn/s/blog_6c60678b0101e847.html
------ For reference only ----------------- ----------------------
actually threading issues
------ For reference only -------- -------------------------------
have not found a solution
f you don't understand my answer, don't ignore it, ask a question.
回复删除