You have an exception and logging it like
Log.e(..., "", ...);
or
Log.e(..., e.getMessage());
does not work. Change the log message to something that is not empty ""
or potentially null as e.getMessage()
, for example, e.toString()
. After that you can see the reason for what caused the exception you're trying to log.
If I had to guess, I'd say it's NetworkOnMainThreadException
i.e. you're doing network ops such as InetAddress.getByName()
on the main UI thread and the target SDK is 11 or higher. Why it work without the uses-sdk
is that if unspecified, targetSdkVersion
defaults to 1 with all the compatibility modes enabled.
For the canonical question about NetworkOnMainThreadException
, see How to fix android.os.NetworkOnMainThreadException?
But it can be so many other things causing the primary exception as well. Fix the logging first.
After you've added the AsyncTask
to offload network operations to a background thread, you'll need to make sure the UI operations are on the UI thread. This is what causes the
ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
AsyncTask
's onPreExecute()
and onPostExecute()
run on the UI thread. That's the easiest way. You can also use Activity
runOnUiThread()
or a Handler
to post Runnable
s to the UI thread.