인터넷에 올라와있는 FTP 클라이언트 예제 어플을 수정하여 안드로이드 FTP 클라이언트 어플리케이션을 제작중입니다.
어플에서 FTP 서버에 접속해서 다운로드를 하는 부분에서 에러가 나는데
코드상에는 에러가 없는데 로그기록에 NullPointerException 이라고 뜨는데 왜그런걸까요?
코드 내용을 하나하나 검색하면서 보니, 다운로드 후 다운 파일을 저장하는 경로가 외부저장소로 되어있어서 내부저장소로 바꾸면 되는 건 줄 알고 바꿨는데, 역시나 NullPointerException라고 뜹니다. 
package dc.mobdev.ftpremote.tasks;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import dc.mobdev.ftpremote.configs.FTPConnection;
import android.content.Context;
import android.os.Environment;
public class DownloadTask extends BaseTask{
public DownloadTask(Context context){
this.init(context);
}
private void init(Context context){
this.context = context;
}
@Override
protected Object doInBackground(Object... params) {
String pathToFileDownload = (String)params[0];
String fileNameToDownload = (String)params[1];
String dirNameToSave = (String)params[2];
return download(pathToFileDownload, fileNameToDownload, dirNameToSave);
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
if((Boolean) result == true){
System.out.println("Download Sucessful!");
}
}
private boolean download(String pathToFileDownload, String fileNameToDownload, String dirNameToSave){
boolean result = false;
String pathToSave = null;
File dir = null;
File fileDownload;
OutputStream os = null;
FileOutputStream fos = null;
try{
String[] keys = FTPConnection.findKeys();
String connectionStr = FTPConnection.readFromSharedPreferenceFile(keys);
this.openConnection(connectionStr);
//pathToSave = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + dirNameToSave; 기존코드
pathToSave = Environment.getDataDirectory().getAbsolutePath() + "/" + dirNameToSave; //수정1
//pathToSave = getFilesDir().getAbsolutePath() + "/" + dirNameToSave; 수정2
dir = new File(pathToSave);
dir.mkdirs();
fileDownload = new File(dir, fileNameToDownload);
fos = new FileOutputStream(fileDownload);
os = new BufferedOutputStream(fos);
result = this.ftpClient.retrieveFile(pathToFileDownload + "/" + fileNameToDownload, os);
return result;
}catch(FileNotFoundException fnfE){
fnfE.printStackTrace();
result = false;
return result;
}catch(IOException ioE) {
ioE.printStackTrace();
result = false;
//result = true;
return result;
}finally{
try {
os.close();
fos.close();
this.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}