点击ActionBar按钮时应用程序崩溃

时间:2015-05-26 15:02:03

标签: android eclipse ftp

我正在使用Eclipse构建应用。当我点击ActionBar按钮时,我的应用程序崩溃了。 任何人都可以帮助我吗?

这是我的logcat:

05-26 16:52:36.523: W/System.err(12808):    at dalvik.system.NativeStart.main(Native Method)
05-26 16:52:36.526: E/AndroidRuntime(12808):    at dalvik.system.NativeStart.main(Native Method)

And now it says 
05-26 17:54:39.416: W/System.err(23613):    at com.bricslab.app.radarofficialapp.Risultati.onOptionsItemSelected(Risultati.java:53)
05-26 17:54:39.427: E/AndroidRuntime(23613):    at com.bricslab.app.radarofficialapp.Risultati.onOptionsItemSelected(Risultati.java:53)

这是我的java文件:

package com.bricslab.app.radarofficialapp;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.TaskStackBuilder;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import android.content.Intent;
import android.support.v4.app.NavUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

public class Risultati extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_risultati);
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.risultati, menu);
        return true; 
    }

    @SuppressLint("SdCardPath")
    public boolean onOptionsItemSelected(MenuItem item) {     

        switch (item.getItemId()) {
        case R.id.button_refresh:
             FTPClient ftpClient = new FTPClient();
             try {

                 ftpClient.connect("ftp.thensc.altervista.org", 21);
                 ftpClient.login("thensc", "richimarti");
                 ftpClient.enterLocalPassiveMode();
                 ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

                 // APPROACH #1: using retrieveFile(String, OutputStream)
                 String remoteFile1 = "/RadarStadium/Risultati.txt";
                 File downloadFile1 = new File("/sdcard/RadarOfficialApp/Risultati.txt");
                 OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
                 boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
                 outputStream1.close();

                 if (success) {
                     System.out.println("File #1 has been downloaded successfully.");
                 }
             } catch (IOException ex) {
                 System.out.println("Error: " + ex.getMessage());
                 ex.printStackTrace();
             } finally {
                 try {
                     if (ftpClient.isConnected()) {
                         ftpClient.logout();
                         ftpClient.disconnect();
                     }
                 } catch (IOException ex) {
                     ex.printStackTrace();
                 }
             }

            return true;
        case R.id.button_edit:
            RisultatiPwd();  
            return true;
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);

            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {

             TaskStackBuilder.create(this)

            .addNextIntentWithParentStack(upIntent)

            .startActivities();

            } else {

            NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
        }



        return super.onOptionsItemSelected(item);   
    }

private void RisultatiPwd() {
    Intent i = new Intent(Risultati.this, RisultatiPwd.class);
    startActivity(i);
    }
}

着名的按钮是button_refresh。

0 个答案:

没有答案