我正在处理 ftp 客户端项目。我在 logcat 中有以下错误。
09-25 19:51:26.884: D/MyFTPClient(9521): Connection Success
09-25 19:51:27.424: W/dalvikvm(9521): dvmFindClassByName rejecting 'UNIX Type: L8'
09-25 19:51:32.309: W/dalvikvm(9521): threadid=12: thread exiting with uncaught exception (group=0x40a89228)
09-25 19:51:32.319: E/AndroidRuntime(9521): FATAL EXCEPTION: AsyncTask #1
09-25 19:51:32.319: E/AndroidRuntime(9521): java.lang.RuntimeException: An error occured while executing doInBackground()
09-25 19:51:32.319: E/AndroidRuntime(9521): at android.os.AsyncTask$3.done(AsyncTask.java:278)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-25 19:51:32.319: E/AndroidRuntime(9521): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.lang.Thread.run(Thread.java:864)
09-25 19:51:32.319: E/AndroidRuntime(9521): Caused by: java.lang.NullPointerException
09-25 19:51:32.319: E/AndroidRuntime(9521): at com.example.ftpclient.MyFTPClient.listftpitems(MyFTPClient.java:112)
09-25 19:51:32.319: E/AndroidRuntime(9521): at com.example.ftpclient.MyFTPClient$connection_test.doInBackground(MyFTPClient.java:69)
09-25 19:51:32.319: E/AndroidRuntime(9521): at com.example.ftpclient.MyFTPClient$connection_test.doInBackground(MyFTPClient.java:1)
09-25 19:51:32.319: E/AndroidRuntime(9521): at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-25 19:51:32.319: E/AndroidRuntime(9521): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-25 19:51:32.319: E/AndroidRuntime(9521): ... 5 more
09-25 19:51:32.399: I/Adreno200-EGLSUB(9521): <ConfigWindowMatch:1991>: Format RGBA_8888.
我的代码是
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showfiles);
lv = (ListView) findViewById(R.id.listview1);
new connection_test().execute("");
}
private class connection_test extends AsyncTask<String, Void,ArrayList<String>> {
ArrayList<String> temparrlist = new ArrayList<String>();
@Override
protected void onPreExecute(){
dialog = ProgressDialog.show(MyFTPClient.this,null,"Please wait...");
}
@Override
protected ArrayList<String> doInBackground(String... connection) {
temparrlist=listftpitems();
return temparrlist;
}
@Override
protected void onPostExecute(ArrayList<String> result) {
dialog.dismiss();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MyFTPClient.this,android.R.layout.simple_list_item_1,result);
lv.setAdapter(arrayAdapter);
}
}
public ArrayList<String> listftpitems(){
try {
//ArrayList<String> arrayList = new ArrayList<String>();
mFTPClient = new FTPClient();
mFTPClient.connect("ftp.ftpaddress",21);
boolean status = mFTPClient.login("userid", "password");
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
if (status == true) {
Log.d(TAG, "Connection Success");
} else {
Log.d(TAG, "Connection failed");
}
} catch (Exception e) {
e.printStackTrace();
}
final FTPFile[] files;
try {
files = mFTPClient.listFiles("/public_html/");
for (FTPFile file : files) {
String details = file.getName();
arrayList.add(details);
Log.d(TAG, details);
}
}catch (IOException e1) {
e1.printStackTrace();
}
return arrayList;
}