2014-01-09 58 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

相关问题