android ftp upload has stopped error

Posted by Goxel Arp on Stack Overflow See other posts from Stack Overflow or by Goxel Arp
Published on 2012-10-13T13:34:37Z Indexed on 2012/11/10 5:00 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|
 class Asenkron extends AsyncTask<String,Integer,Long> 
    { 

        @Override
         protected Long doInBackground(String... aurl) 
        {
         FTPClient con=null; 
        try `
        { 
            con = new FTPClient(); 
            con.connect(aurl[0]); 

            if (con.login(aurl[1], aurl[2])) 
            { 
                con.enterLocalPassiveMode(); // important!
                 con.setFileType(http://FTP.BINARY_FILE_TYPE); 
                FileInputStream in = new FileInputStream(new File(aurl[3])); 
                boolean result = con.storeFile(aurl[3], in); 
                in.close(); 
                con.logout(); 
                con.disconnect();
             } 
        } 
        catch (Exception e) 
        {
            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
        return null;
    }



    protected void onPostExecute(String result) {}
}

I AM USING THIS CLASS LIKE BELOW.THERE IS BUTTON AND WHENEVER I CLICK THE BUTTON IT SHOULD START FTP UPLOAD PROCESS IN BACKGROUND BUT I GET "PROGRAM HAS STOPPED UNFORTUNATELY" ERROR. Assume that The ftp address and username password pathfile sections are true and I get the internet and network permissions already by the way ...

    button1.setOnClickListener(new OnClickListener() 
    {
        public void onClick(View arg0) 
        {
            new Asenkron().execute("ftpaddress","username","pass","pathfileon telephone"); 
        }
   });

And here is the logcat for you to analyse the potential error and help me ...

10-13 13:01:25.591: I/dalvikvm(633): threadid=3: reacting to signal 3
10-13 13:01:25.711: I/dalvikvm(633): Wrote stack traces to '/data/anr/traces.txt'
10-13 13:01:25.921: D/gralloc_goldfish(633): Emulator without GPU emulation detected.
10-13 13:01:31.441: W/dalvikvm(633): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
10-13 13:01:31.461: E/AndroidRuntime(633): FATAL EXCEPTION: AsyncTask #1
10-13 13:01:31.461: E/AndroidRuntime(633): java.lang.RuntimeException: An error occured while executing doInBackground()
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.lang.Thread.run(Thread.java:856)
10-13 13:01:31.461: E/AndroidRuntime(633): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.os.Handler.<init>(Handler.java:121)
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.widget.Toast$TN.<init>(Toast.java:317)
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.widget.Toast.<init>(Toast.java:91)
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.widget.Toast.makeText(Toast.java:233)
10-13 13:01:31.461: E/AndroidRuntime(633):  at com.example.ftpodak.ODAK$Asenkron.doInBackground(ODAK.java:74)
10-13 13:01:31.461: E/AndroidRuntime(633):  at com.example.ftpodak.ODAK$Asenkron.doInBackground(ODAK.java:1)
10-13 13:01:31.461: E/AndroidRuntime(633):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
10-13 13:01:31.461: E/AndroidRuntime(633):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-13 13:01:31.461: E/AndroidRuntime(633):  ... 5 more

By the way I changed the relevant code like that ;

instead of

catch (Exception e) 
  {
   Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
  }

I replaced with this code

catch (Exception e) 
  {
     HATA=e.toString();
  }

And I added the code to button

textview1.setText(HATA);

So I can see the error on the textview and it is writing that "Android java.net.UnknownHostException: Host is unresolved"

But i know that the ftp server is correct and I check the ftp server from the AndFTP application. With the same address login and pass information ftp server is working.So the problem is in my code I think.Any help will be too much appreciated.Anyone who can help me I can give teamviewer to analyse what is the problem ...

© Stack Overflow or respective owner

Related posts about android

Related posts about networking