1

This thing worked for over an year and suddenly started to return an Exception

here's some of AsynkTask :

URLConnection conn = url.openConnection();
try
{
    reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    //the rest of the code doesn't go - exception works out        
}        
catch(Exception ex)
{
    Error = ex.getMessage();    
}

now, the url is valid - I copy it from debugger and paste in browser - it returns me a very fine json as it should. And this whole thing worked for over an year and now it catches an Exception - FileNotFound

what it could be, how can I solve it?

alterfox
  • 1,675
  • 3
  • 22
  • 37
Lyubov Alekseeva
  • 209
  • 1
  • 4
  • 10

1 Answers1

0

Try int status = conn.getResponseCode(); to see the status.
Then try InputStream error = conn.getErrorStream();
These methods are from HttpURLConnection.

You probably get FileNotFoundException as an indication that the web server returned a 404. This is javadoc for public InputStream getErrorStream():

Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do.

This method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.

Returns: an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.


Also, for a case similar to yours ("I was receiving the page fine in the browser, but got a 404 when I tried to access it via the HttpURLConnection."), check this answer to see adding some request properties:
URLConnection FileNotFoundException for non-standard HTTP port sources

Community
  • 1
  • 1
alterfox
  • 1,675
  • 3
  • 22
  • 37