2014-01-09 78 views
-3

我有一個FTP客戶端發送正常的文件,但是當我按下菜單,或在手機上通話,它不會在後臺發送和關閉應用程序。這是正常的嗎?我發送一個文件,當你幾乎完成時,有人打電話給我,並清除我的上傳,我應該重新開始?錯誤產生的原因:android.app.SuperNotCalledException:

謝謝。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.informacoes); 
    assunto  = (EditText)findViewById(R.id.tf_assunto); 
    comentario = (EditText)findViewById(R.id.tf_comentario); 
    onde  = (EditText)findViewById(R.id.tf_onde); 
    if(caminhoArquivo != null){ 
     arquivo = new File(caminhoArquivo); 
    } 
    else{ 
     finish(); 
    } 
    enviar(); 
    sair(); 

    enviarSegundoPlano = new AsyncTask<Void, Void, Void>(){ 
     @Override 
     protected Void doInBackground(Void... params) { 
      nomeArquivo = arquivo.getName(); 
      return null; 
     } 
    }; 
    enviarSegundoPlano.execute(); 
} 

    private void enviarArquivo(final File arquivo){ 
    Tarefa tarefa = new Tarefa(mProgressDialog){ 
     @Override 
     protected String doInBackground(String... params) { 
      try{ 
       //ftp.abort(); 
       if(conecta(usuario, senha, host)){ 
        State wifi = Principal.conexao.getNetworkInfo(1).getState(); 
        final String subPasta = txAssunto; 
        FileChannel fileChannelEntrada = new RandomAccessFile(arquivo, "r").getChannel(); 
        ftp.changeWorkingDirectory(pasta); 
        ftp.mkd(subPasta); 
        ftp.changeWorkingDirectory(subPasta); 
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE); 
        if(wifi == NetworkInfo.State.CONNECTED){ 
         ftp.enterLocalPassiveMode(); 
        } 
        WritableByteChannel saida = Channels.newChannel(ftp.storeFileStream(arquivo.getName())); 
        //ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16384); 
        ByteBuffer byteBuffer = ByteBuffer.allocate(90); 
        byteBuffer.clear(); 
        while(fileChannelEntrada.read(byteBuffer) != -1){ 
         byteBuffer.flip(); 
         saida.write(byteBuffer); 
         byteBuffer.clear(); 
         publishProgress(getPorcentagem(fileChannelEntrada.size(), fileChannelEntrada.position())); 
         if(fileChannelEntrada.read(byteBuffer) > 0 && fileChannelEntrada.read(byteBuffer) < 100){ 
          resposta = true; 
         } 
        } 
       } 
      } 
      catch(Exception e){ 
       resposta = false; 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(String result) { 
      enviarArquivo(arquivoTXT, true); 
      if(resposta){ 
       try{ 
        new Thread(){ 
         public void run(){ 
          try{ 
           Email email = new Email(Principal.emailUsuario, txAssunto, txOnde, txComentario); 
           email.enviarEmail(); 
          } 
          catch(Exception e){ 
           e.printStackTrace(); 
          } 
         } 
        }.start(); 
        mostrarTextoTela("Enviado com Sucesso!"); 
       }catch(Exception e){e.printStackTrace();} 
      } 
      else{ 
       mostrarTextoTela("Erro ao Enviar"); 
      } 
      super.onPostExecute(result); 
      finish(); 
     } 
    }; 
    tarefa.execute(); 
} 

logcat的

01-09 07:09:26.789: D/dalvikvm(21014): GC_EXTERNAL_ALLOC freed 57K, 48% free 2808K/5379K, external 511K/517K, paused 195ms 
01-09 07:10:09.140: D/dalvikvm(21534): GC_EXTERNAL_ALLOC freed 56K, 48% free 2803K/5379K, external 511K/517K, paused 38ms 
01-09 07:10:24.281: D/dalvikvm(21534): GC_CONCURRENT freed 215K, 47% free 3026K/5639K, external 816K/996K, paused 4ms+3ms 
01-09 07:12:01.234: W/IInputConnectionWrapper(21534): showStatusIcon on inactive InputConnection 
01-09 07:12:07.101: W/dalvikvm(22169): threadid=9: thread exiting with uncaught exception (group=0x40018578) 
01-09 07:12:07.109: E/AndroidRuntime(22169): FATAL EXCEPTION: AsyncTask #1 
01-09 07:12:07.109: E/AndroidRuntime(22169): java.lang.RuntimeException: An error occured while executing doInBackground() 
01-09 07:12:07.109: E/AndroidRuntime(22169): at android.os.AsyncTask$3.done(AsyncTask.java:200) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.lang.Thread.run(Thread.java:1019) 
01-09 07:12:07.109: E/AndroidRuntime(22169): Caused by: java.lang.NullPointerException 
01-09 07:12:07.109: E/AndroidRuntime(22169): at br.com.marcio.Informacoes$1.doInBackground(Informacoes.java:75) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at br.com.marcio.Informacoes$1.doInBackground(Informacoes.java:1) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at android.os.AsyncTask$2.call(AsyncTask.java:185) 
01-09 07:12:07.109: E/AndroidRuntime(22169): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
01-09 07:12:07.109: E/AndroidRuntime(22169): ... 4 more 
+2

安置自己的Logacat.Asü標題這個問題華南簡介錯誤發生,但ü沒有定義的情況時,發生錯誤。請更多地解釋你的問題。 –

+0

你有沒有'onPause'或'OnResume'等你叫'super.pause()'或'super.onResume'? –

+0

請仔細檢查你的生命週期方法。 –

回答

0
enviarSegundoPlano = new AsyncTask<Void, Void, Void>(){ 
    @Override 
    protected Void doInBackground(Void... params) { 
     if(arquivo!=null) 
     nomeArquivo = arquivo.getName(); 
     else{ 
     Log.d("LOG_APP", "arquivo null"); 
     // ... 
     } 
     return null; 
    } 
}; 
enviarSegundoPlano.execute(); 

處理這種情況時arkuivo爲空

+0

謝謝,解決了這個問題 – user3175958

相關問題