I have been testing the Apache commons API 3.1 on android 2.1,and it was working fine so far. Now I'm trying to use it on Android ICS(4.0) but I'm running into a problem: the application throws a unhandled exception when I used the "ftp.connect" Command
Here is just a simple code, just to show when the application crashes:
FTPClient ftp = new FTPClient(); //so far is ok
try {
ftp.connect("127.0.0.1",21); //<-throws a unhandled exception (used to work on android 2.1)
} catch (Exception e){
Log.e("error",e.getMessage());// it doesn't reach this block
}
This is what I have in my logCat:
W/dalvikvm(1105): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
Does anyone have any idea of what's happening?
I guess you are facing the popular NetworkOnMainThreadException. You need to have the network and internet access statements in a separate thread (not in the same thread as main) or in an Async Task. More explanation in an older StackOverflow thread here