1

I will upload a File via FTP and Android. The problem is that I can not connect to the server. I use the http://commons.apache.org/ FTP 1.4.1 Libary.

Here is my code:

FTPClient ftpClientUp = new FTPClient();

try {
    ftpClientUp.connect(InetAddress.getByName("myftpserver.tld"));
} 

catch (Exception e) {
    Toast toast = Toast.makeText(getApplicationContext(), "Allways come this message :/" Toast.LENGTH_SHORT), Toast.LENGTH_SHORT);
    toast.show();
}

And this is the error message I am getting:

android.os.NetworkOnMainThreadException

Can anybody help me?

Calcolat
  • 878
  • 2
  • 11
  • 22
TomStr
  • 51
  • 5

1 Answers1

1

You should make network requests in a separate thread (not in main, UI thread). You can find more info here.

Community
  • 1
  • 1
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62