Parse exception: In row 1, column 0: item not found

I have a strange problem. I get the following error, which causes a forced close:

org.apache.harmony.xml.ExpatParser $ ParseException: row 1 column 0: element is missing from org.apache.harmony.xml.ExpatParser.parseFragment (ExpatParser.java:508) at org.apache.harmony.xml.ExpatParser. parseDocument (ExpatParser.java:467) at org.apache.harmony.xml.ExpatReader.parse (ExpatReader.java:329) at org.apache.harmony.xml.ExpatReader.parse (ExpatReader.java:286)

After clicking the "Force Close" button, the activity will be recreated, and the parsing will end without a hitch. I use the following code snippet inside doInBackground for AsyncTask:

URL serverAddress = new URL(url[0]);

HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();

InputStream stream = connection.getInputStream();

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();

XMLReader xr = sp.getXMLReader();

xr.parse(new InputSource(stream));  // The line that throws the exception

, ? BufferedInputStream ? .: (

.

: , HttpURLConnection.getResponseCode() -1 , InputStream, , .

+5
6
HTTPURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);

. HTTPURLConnection HTTPURLConnection? GET. setDoOutput(true) POST.

URLConnection connection = serverAddress.openConnection();

. , , POST ( ). connection.connect(), , connection.getInputStream(), .

: ?

BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
for (String line; (line = reader.readLine()) != null;) {
    System.out.println(line);
}
reader.close();
+5

, , . , , xr.parse(). InputStream, XML-. , InputSource

: InputStream InputSource url .

InputSource a =  new InputSource(url_string);   

url_string - URL. , ... , . , , !

+2

Per InputStream javadoc , EOF. , Socket - inStream.read().

BufferedReader, . readLine() , HTTP.

+1

URL- . AsyncTask , .

+1

. InputStream Scanner, . XML-.

, Scanner. InputStream .

.

+1

I ran into the same problem and made no sense, because I was dealing directly with InputSource. When I changed the code to output the result to a string before parsing xml, I discovered that the problem was simply the wrong name for the web service method and that the error message reported by this service was a killer.

0
source

All Articles