Android:FTP-Connection不起作用,无法通过通用图像加载器显示图像

时间:2013-05-01 13:35:48

标签: android ftp

当我连接到我的在线ftp服务器(ftp.spicy-software.com)时,它不起作用,没有错误或崩溃。只是一个空白的布局。但是,当我连接到我的LOCAL ftp服务器时,它可以工作并显示图片。为什么??

我正在连接我的本地ftp服务器(Local-IP:192.168.99.105),效果很好,图片将显示在gridview中:

enter image description here

    new FtpTask().execute();

    private class FtpTask extends AsyncTask<Void, Void, FTPClient> {
     protected FTPClient doInBackground(Void... args) {
         //connectFTP("192.168.99.105", "Username", "Password", 21);
         connectFTP("ftp.spicy-software.com", "USername1", "Passweord", 21);
        return null;

     }

     protected void onPostExecute(FTPClient result) {
         Log.v("FTPTask","FTP connection complete");
     }
    }

connectFTP()函数:

    public void connectFTP(String host, String username, String password, int port){

    try {
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect(host, port);
        ftpClient.enterLocalPassiveMode();
        ftpClient.login(username, password);
        ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
        ftpClient.changeWorkingDirectory("GetThePicture/pictures/");
        Log.v("FTP STATUS: ",ftpClient.getStatus());


        FTPFile[] files = ftpClient.listFiles();

        for (FTPFile file : files) {
            Log.v("File: ", "http://spicy-software.com/GetThePicture/pictures/"+file.getName());
            imageUrls.add("http://www.spicy-software.com/GetThePicture/pictures/"+file.getName());
            imageNames.add(file.getName());
        }

        Log.v("FILE_1: ", imageUrls.get(1));
    } catch (Exception e) {
        Log.v("Error", ""+e);
        e.printStackTrace();
    }
}

但是当我尝试连接到ftp.spicy-software.com在线ftp服务器时,它不起作用:

logcat的:

05-01 15:31:50.280: D/AbsListView(2136): Get MotionRecognitionManager

05-01 15:31:50.345: D/libEGL(2136): loaded /system/lib/egl/libEGL_mali.so
05-01 15:31:50.350: D/libEGL(2136): loaded /system/lib/egl/libGLESv1_CM_mali.so
05-01 15:31:50.350: D/libEGL(2136): loaded /system/lib/egl/libGLESv2_mali.so
05-01 15:31:50.355: D/(2136): Device driver API match
05-01 15:31:50.355: D/(2136): Device driver API version: 10
05-01 15:31:50.355: D/(2136): User space API version: 10 
05-01 15:31:50.355: D/(2136): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
05-01 15:31:50.390: D/OpenGLRenderer(2136): Enabling debug mode 0
05-01 15:31:53.605: V/FTP STATUS:(2136): 211-Status of 'ftp.easyname.eu'

05-01 15:31:53.605: V/FTP STATUS:(2136): 211-Connected from 109.164.221.167 (109.164.221.167)

05-01 15:31:53.605: V/FTP STATUS:(2136): 211-Logged in as 35221ftp1

05-01 15:31:53.605: V/FTP STATUS:(2136): 211-TYPE: BINARY, STRUcture: File, Mode: Stream

05-01 15:31:53.605: V/FTP STATUS:(2136): 211-No data connection

05-01 15:31:53.605: V/FTP STATUS:(2136): 211 End of status

05-01 15:31:53.910: W/dalvikvm(2136): dvmFindClassByName rejecting 'UNIX Type: L8'
05-01 15:31:55.285: D/dalvikvm(2136): GC_CONCURRENT freed 167K, 10% free 12399K/13703K, paused 4ms+2ms, total 24ms
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/1.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/2.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/3.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/4.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/5.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/6.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/7.jpg
05-01 15:31:55.775: V/File:(2136): http://spicy-software.com/GetThePicture/pictures/8.jpg
05-01 15:31:55.775: V/FILE_1:(2136): http://www.spicy-software.com/GetThePicture/pictures/2.jpg
05-01 15:31:55.780: V/FTPTask(2136): FTP connection complete

1 个答案:

答案 0 :(得分:0)

问题是AsyncTask没有在主线程中运行而且代码太快了! 所以它尝试使用图像加载器加载那些图像BEFORE asynctask已经完成...