Apache Commons API will not work on Android ICS (4.0)

I tested the Apos Commons API 3.1 on Android 2.1, and it worked fine so far. Now I'm trying to use it in Android ICS (4.0), but I have a problem: the application throws an unhandled exception when I used the command "ftp.connect"

Here is just 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 an idea of โ€‹โ€‹what is going on?

+4
source share
1 answer

I think you came across a popular NetworkOnMainThreadException . You need to have network and Internet access operators in a separate stream (not in the same stream as the main one), or in the Async task. More explanation in an older StackOverflow article here

+4
source

Source: https://habr.com/ru/post/1445782/


All Articles