lordlee.cz
lordlee.cz

Reputation: 1

Downloading file from FTP

I have an app which every 3 minutes download file from FTP server and then read it. My problem is that this FTP transfer works only first time when app is launched, when timer runs this method next time, app crashes. Here is how I call the method using timer

    Timer t2 = new Timer(180000, new ClockListener2());
    t2.start();

and then

   public class ClockListener2 implements ActionListener {
    public void actionPerformed(ActionEvent ae) {
    downloadFtp();
    }

and now FTP transfer method

public void downloadFtp() {
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;
    try {
        client.connect("192.168.1.102");
        client.login("anonymous", "");
        String filename = "text.txt";
        fos = new FileOutputStream(filename);
        client.retrieveFile("/" + filename, fos);
        client.logout();
        client.disconnect();
        if (fos != null) {
            fos.close();}
    } catch (Exception e) {
        e.printStackTrace();
    }
    }

did anyone met this problem before? What could be wrong?

Thanks.

Upvotes: 0

Views: 179

Answers (1)

Jeff Liu
Jeff Liu

Reputation: 366

You could connect your device with ADB to view the logs printed by your device (see logcat). If your app is crashed, you will see some FATAL exception trace (it's often very helpful) such as:

07-24 09:33:59.285: ERROR/AndroidRuntime(4858): FATAL EXCEPTION: main
    java.lang.NullPointerException
    at ***.daifan.activity.***Activity.onCreateOptionsMenu(***ListActivity.java:96)
    at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:44)
    at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
    at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:65)
    at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:165)
    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:417)
    at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:768)
    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3009)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4514)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
    at dalvik.system.NativeStart.main(Native Method)

Upvotes: 1

Related Questions