Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:08:55+00:00 2026-06-16T07:08:55+00:00

I am writing a small ftp client using apache lib. I am returning list

  • 0

I am writing a small ftp client using apache lib. I am returning list of files in ArrayList

import java.io.IOException;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

import android.os.AsyncTask;
import android.util.Log;

public class myftpTask extends AsyncTask<String, Void, List<FTPFile>> {
    public FTPFile[] FTPFile;
    FTPClient mFtp = new FTPClient();

    @Override
    protected List<FTPFile> doInBackground(String... params) {
        List<FTPFile> myFiles = new ArrayList<FTPFile>();
        // TODO Auto-generated method stub
        try {
            mFtp.connect(params[0], 21);

            if (FTPReply.isPositiveCompletion(mFtp.getReplyCode())) {
                mFtp.login(params[1], params[2]);
                mFtp.enterLocalPassiveMode();
                mFtp.changeWorkingDirectory("/public_html");
                FTPFile files[] = mFtp.listFiles();



                for (int i = 0; i < files.length; i++) { // does not enter here
                    //Log.d("F-> " , ((FTPFile) files[i]).getName().toString());
                    //myFiles.add((FTPFile) files[i]).getName().toString());
                    myFiles.add(files[i]);
                }
                Log.v("Files", myFiles.toString());
                mFtp.disconnect();
            }
        } catch (SocketException e) {
            try {
                mFtp.disconnect();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //return 1;
        return myFiles;

    }
}

And I am receiving it like this

import java.util.List;

import org.apache.commons.net.ftp.FTPFile;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView lv = (ListView) findViewById(R.id.listView1);

        List<FTPFile> listofFiles;

        listofFiles = (List<FTPFile>) new myftpTask().execute(
                "*****", "*****", "******");

        ArrayAdapter<FTPFile> arrayAdapter = new ArrayAdapter<FTPFile>(this,
                android.R.layout.simple_list_item_1, listofFiles);
        lv.setAdapter(arrayAdapter);
    }



}

But it throwing an exception of cannot cast to list.

Where is the problem?

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:08:57+00:00Added an answer on June 16, 2026 at 7:08 am

    does this compile

     listofFiles = (List<FTPFile>) new myftpTask().execute(
                    "*****", "*****", "******");
    

    ???

    newmyftpTask().execute(); returns object from this type AsyncTask<String, Void, List<FTPFile>>

    use this instead

     listofFiles = (List<FTPFile>) new myftpTask().execute(
                        "*****", "*****", "******").get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small read-only FTP-like server. Client says give me that file and
I am currently writing a small application in Windows Mobile using CF.NET. The application
I'm writing small XMPP server using boost::asio and I want to unit-test my code.
I am writing small app, using Play Framework 2.0 which uses Ebean as ORM.
I'm writing a small RMI based Chat application. The idea is: the Client registers
I'm writing small hello world type of program, which groups same files by different
I'm writing small web application on java with hibernate, and I see strange thing
I am writing a small application using Rails 3. In one part of it
I'm writing small VB.Net app which should build reports based on data gathered from
I am writing a small app to automate deployments. Basically, it checks an ftp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.