안드로이드용 FTP 클라이언트 어플리케이션을 만들고 있습니다.
FTP서버의 파일 리스트를 폰에서 리스트뷰로 띄우고 싶습니다.
어댑터뷰를 이용해 파일 리스트를 리스트뷰에 띄우려는데 에러가 발생하는데,
list.setAdapter(Adapter);
구문에서 넘어가지 않습니다.
로그캣이랑 소스첨부합니다.

public class MainActivity extends Activity implements OnClickListener {
private FTPClient ftp = null; // FTP Client 객체
private FileInputStream fis = null; // File Input Stream
private FileOutputStream fos = null; // File Output Stream
private File uploadfile; // File 객체
private File downloadfile; // File 객체
private Context context = this;
private final String FileName = "readme.txt";
private final String TAG = "@@@@";
private Button btn_conn, btn_disconn, btn_upload, btn_download;
private ProgressDialog pDialog;
private boolean progress_state = false;
private final int progress_bar_type = 0;
private long intTotalFileSize = 0;
private String progress_message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_conn = (Button) findViewById(R.id.btn_conn);
btn_disconn = (Button) findViewById(R.id.btn_disconn);
btn_upload = (Button) findViewById(R.id.btn_upload);
btn_download = (Button) findViewById(R.id.btn_download);
ListView list = (ListView) findViewById(R.id.list);
list.setAdapter(Adapter);
btn_conn.setOnClickListener(this);
btn_disconn.setOnClickListener(this);
btn_upload.setOnClickListener(this);
btn_download.setOnClickListener(this);
uploadfile = new File(Environment.getExternalStorageDirectory()
.toString() + "/" + FileName);
downloadfile = new File(Environment.getExternalStorageDirectory()
.toString() + "/" + FileName);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_conn:
new ConnTask().execute("Conn");
break;
case R.id.btn_disconn:
new ConnTask().execute("Disconn");
break;
case R.id.btn_upload:
progress_state = true;
progress_message = "Uploading File";
new ConnTask().execute("Upload");
break;
case R.id.btn_download:
progress_message = "Downloading File";
new ConnTask().execute("Download");
break;
}
}
private class ConnTask extends AsyncTask<String, String, String> {
protected void onProgressUpdate(String... progress) {
pDialog.setProgress(Integer.parseInt(progress[0]));
}
@SuppressWarnings("deprecation")
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.d("@@@", "Test start");
if (progress_state) {
showDialog(progress_bar_type);
}
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progress_state = false;
if (pDialog != null) {
if (pDialog.isShowing()) {
pDialog.dismiss();
}
}
}
@Override
protected String doInBackground(String... params) {
if (params[0].equals("Conn")) {
ConnFTP();
} else if (params[0].equals("Disconn")) {
DisconnFTP();
} else if (params[0].equals("Upload")) {
Log.d(TAG, "FileUpload");
try {
ftp.changeWorkingDirectory("/"); // 작업 디렉토리 변경
ftp.setFileType(FTP.BINARY_FILE_TYPE); // 업로드 파일 타입 셋팅
fis = new FileInputStream(uploadfile); // 업로드할 File 생성
intTotalFileSize = fis.getChannel().size();
ftp.setCopyStreamListener(new CopyStreamAdapter() {
@Override
public void bytesTransferred(long arg0, int arg1,
long arg2) {
super.bytesTransferred(arg0, arg1, arg2);
int percent = (int) (arg0 * 100 / intTotalFileSize);
publishProgress("" + percent);
}
});
ftp.storeFile(uploadfile.getName(), fis); // File 업로드
Log.d(TAG, "FileUpload / success");
} catch (IOException e) {
Log.e(TAG, "FileUpload = " + e);
} finally {
if (fis != null) {
try {
fis.close(); // Stream 닫기
} catch (IOException e) {
Log.e(TAG, "FileUpload / fis.close()= " + e);
}
}
}
Log.d(TAG, "FileUpload / end");
Logout();
} else if (params[0].equals("Download")) {
Log.d(TAG, "FileDownload");
try {
ftp.changeWorkingDirectory("/"); // 작업 디렉토리 변경
ftp.setFileType(FTP.BINARY_FILE_TYPE); // 다운로드 파일 타입 셋팅
fos = new FileOutputStream(downloadfile); // 다운로드할 File 생성
ftp.retrieveFile(downloadfile.getName(), fos);
Log.d(TAG, "FileDownload / success");
} catch (IOException e) {
Log.e(TAG, "FileDownload = " + e);
} finally {
if (fos != null) {
try {
fos.close(); // Stream 닫기
} catch (IOException e) {
Log.e(TAG, "FileDownload / fos.close() = " + e);
}
}
}
Log.d(TAG, "FileDownload / end");
Logout();
}
return null;
}
}
private void ConnFTP() {
Log.d(TAG, "ConnFTP");
try {
ftp = new FTPClient(); // FTP Client 객체 생성
ftp.setRemoteVerificationEnabled(false);
ftp.setControlEncoding("euc-kr"); // 문자 코드를 euc-kr로 인코딩
ftp.connect("@@.@@@.@@@.@@", @@); // 서버접속 " "안에 서버 주소 입력 또는
// "서버주소",// 포트번호
ftp.login("@@@", "@@@@"); // FTP 로그인 ID, PASSWORLD 입력
ftp.enterLocalPassiveMode(); // Passive Mode 접속일때
Log.d(TAG, "ConnFTP / success");
viewFTPFileList();
} catch (IOException e) {
Log.e(TAG, "ConnFTP = " + e);
}
Log.d(TAG, "ConnFTP / end");
}
private void viewFTPFileList() {
Log.d(TAG, "viewFTPFileList");
ArrayList<FTPFile> listFtpFile = new ArrayList<FTPFile>();
FTPFile[] listFiles;
try {
listFiles = this.ftp.listFiles();
for (FTPFile ftpFile : listFiles) {
listFtpFile.add(ftpFile);
}
Log.d(TAG, "1");
// String temp = path.substring(1, path.length());
ArrayList newArray = new ArrayList();
// newArray.add(path);
newArray.add(listFtpFile);
Log.d(TAG, "2");
ArrayAdapter<FTPFile> Adapter;
Log.d(TAG, "3");
Adapter = new ArrayAdapter<FTPFile>(this,
android.R.layout.simple_list_item_1, listFtpFile);
Log.d(TAG, "4");
ListView list = (ListView) findViewById(R.id.list);
Log.d(TAG, "5");
list.setAdapter(Adapter);
Log.d(TAG, "6");
Adapter.notifyDataSetChanged();
} catch (IOException ioE) {
ioE.printStackTrace();
}
/*
Log.d(TAG, "viewFTPFileList");
try {
FTPFile[] ftpFiles = ftp.listFiles("/");
if (ftpFiles != null) {
for (int i = 0; i < ftpFiles.length; i++) {
Log.d("@@@@", "ftpFile = " + ftpFiles[i]);
}
}
} catch (IOException e) {
Log.e(TAG, "viewFTPFileList = " + e);
}*/
}
private void DisconnFTP() {
Log.d(TAG, "DisconnFTP");
if (ftp != null && ftp.isConnected()) {
try {
ftp.disconnect(); // 접속 끊기
Log.d(TAG, "DisconnFTP / success");
} catch (IOException e) {
Log.e(TAG, "DisconnFTP = " + e);
}
Log.d(TAG, "DisconnFTP / end");
} else {
Log.d(TAG, "DisconnFTP / else");
}
}
private void Logout() {
Log.i(TAG, "Logout");
try {
ftp.logout();// FTP Log Out
Log.i(TAG, "Logout / success");
} catch (IOException e) {
Log.e(TAG, "FileUpload / fis.logout();= " + e);
}
Log.i(TAG, "Logout / end");
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type: // we set this to 0
pDialog = new ProgressDialog(this);
pDialog.setMessage(progress_message + ". Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
DisconnFTP();
Logout();
return false;
}
});
pDialog.show();
return pDialog;
default:
return null;
}
}
}