I am working on a fairly simple Android application that should get the last modified / updated date for the webpage, but it seems to crash with the following message
05-27 10: 50: 15.581 2638-2652 / android.process.acore E / DictionaryBackupAgent: could not be read from the cursor
05-27 10: 50: 20.658 2638-2647 / android.process.acore E / StrictMode: The resource was received in the associated stack trace, but was never released. See Java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: The explicit completion method is not called "close"
at dalvik.system.CloseGuard.open (CloseGuard.java:184)
in android.os.ParcelFileDescriptor. (ParcelFileDescriptor.java:180)
on android.os.ParcelFileDescriptor $ 1.createFromParcel (ParcelFileDescriptor.java:916)
in android.os.ParcelFileDescriptor $ 1.createFromParcel (ParcelFileDescriptor.java:906)
in android.app.IBackupAgent $ Stub.onTransact (IBackupAgent.java:57)
in android.os.Binder.execTransact (Binder.java-00-0046)
Part of my code is below. The getLastModified () method seems to cause this failure, not knowing why.
private class Connection extends AsyncTask<String, Void, Integer> {
@Override
protected String doInBackground(String... urls) {
String response = "This";
URL url = null;
try {
url = new URL(urls[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection con = null;
try {
con = (HttpURLConnection) url.openConnection();
con.connect();
long date = con.getLastModified();
response = Long.toString(date);
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result) {
mainText2.setText(result);
}
}
@Override
public void onClick(View v) {
Connection task = new Connection();
task.execute(new String[] { "http://www.example.com/files/index.html" });
}
What am I missing here? Any help is appreciated!
ayush source
share