Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:16:58+00:00 2026-06-12T18:16:58+00:00

class Asenkron extends AsyncTask<String,Integer,Long> { @Override protected Long doInBackground(String… aurl) { FTPClient con=null; try

  • 0
 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 …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:16:59+00:00Added an answer on June 12, 2026 at 6:16 pm

    You can get a hint of the problem from this line: Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare(). You’re trying to execute a UI operation from a thread that is not the main thread. All UI changes should be executed from the main thread.

    Comment out this line and it’ll work:

    Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    

    Instead of showing the toast to notify the user of the exception, use a boolean to tell the Activity subclass(that calls the async task) that there had been an exception and show a toast accordingly.

    EDIT- The Library you’re using might not be able to do the job, so you can just shift to a new library, like the apache commons ftp. Refer this blog to see how to use it.

    EDIT2- If in con.connect(aurl[0]);, aurl[0] already contains http://***, you’ll have to remove http:// because the ftp client appends it later (causing the unknown host). Also change this line con.setFileType(FTP.BINARY_FILE_TYPE);(remove the http:// part)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class GoogleMusicAdapter extends TestFragmentAdapter implements TitleProvider { public GoogleMusicAdapter(FragmentManager fm) { super(fm); } @Override
class Program { static void Main(string[] args) { Console.WriteLine(Fib 1: ); Console.ReadLine(); } long
class Model_Core_NodeContents extends Zend_Db_Table_Abstract { protected $_name = 'node_contents'; protected $_referenceMap = array( Page
class X extends Map[String, String] { def x(): X = { X() } //
class Test { public static void main(String[] args) throws Exception { Test t =
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
class A { } class B extends A { } class TestType { public
class GameFrameClass extends javax.swing.JFrame { public void MyFunc() { UserButton.setText(Str); UserButton.addActionListener(new java.awt.event.ActionListener() { public
Class c extends thread static Queue<Socket> socketQueue Make connection to another server or client
class ZiggyTest{ public static void main(String[] args){ RunnableThread rt = new RunnableThread(); Thread t1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.