2

I am Trying to upload jpg Image to FTP server using SimpleFTP.

Following is My Code:

try 
{
    SimpleFTP ftp = new SimpleFTP();

    ftp.connect("URL", 21, "User Name", "Password");

    // Set binary mode.
    ftp.bin();

    // Change to a new working directory on the FTP server.
    ftp.cwd("/demo1/RChatAPI/usrPhotos/");

    // Upload some files.
    ftp.stor(new File("/mnt/sdcard/aaa.jpg"));              

    // Quit from the FTP server.
    ftp.disconnect();

}
catch (IOException e) 
{
     Log.v("Upload","Error Is:"+e);
}

And I got following error java.lang.NoClassDefFoundError

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Nirav Dabhi
  • 341
  • 1
  • 7
  • 29

2 Answers2

0

Have you included this jar to your lib folder?

kospol
  • 377
  • 3
  • 9
  • OfCorse I had Added SimpleFTP.jar in my library then also same result. – Nirav Dabhi Apr 02 '14 at 04:47
  • Then try to clean your project and make sure the library is included to your build path. (Project, properties, Java Build Path, add jar. Then go to the next tab (Order and export) and make sure the library is checked. – kospol Apr 02 '14 at 04:58
  • Hmm Ya I had Checked this Jar file in Order and Export Tab then also same error! Is there any other reason for that If you Know. – Nirav Dabhi Apr 02 '14 at 05:00
  • It's strange, I found [another](http://stackoverflow.com/questions/12144026/android-ftp-upload-error-noclassdeffounderror) problem with this. Are you sure the SimpleFTP works with Android? – kospol Apr 02 '14 at 05:06
  • Ofcore it works in Android. Dont WOrry Finally I had Got the solution for that. But Thanks alot Dude! – Nirav Dabhi Apr 02 '14 at 05:34
  • See My Answer in my Own Question for Solution! – Nirav Dabhi Apr 02 '14 at 05:40
0

Finally I Got the solution Of My Question.

public class MainActivity extends Activity 
{
    Button b1;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        b1=(Button)findViewById(R.id.button1);

        b1.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View arg0) 
            {
                UploadVideo async = new UploadVideo();
                async.execute();
            }
        });
    }

    class UploadVideo extends AsyncTask<String, Integer, String> 
    {
           @Override
          protected String doInBackground(String... params) 
           {
           // ftpClient=uploadingFilestoFtp();
               try 
               {
                    SimpleFTP ftp = new SimpleFTP();

                    ftp.connect("Your URL", 21, "User Name", "Password");

                    ftp.bin();

                    //  Change to a new working directory on the FTP server.
                    ftp.cwd("/demo1/RChatAPI/usrPhotos/");

                    //  Upload some files.
                    ftp.stor(new File("mnt/sdcard/aaa.jpg"));

                    // Quit from the FTP server.
                    ftp.disconnect();

               } 
               catch (Exception e) 
               {
                   e.printStackTrace();
               }

               return null;
           }

           @Override
          protected void onPreExecute() 
           {
               super.onPreExecute();
               // dialog.show();
          }

           @Override
          protected void onPostExecute(String result)
          {
               // TODO Auto-generated method stub
               super.onPostExecute(result);
               Toast.makeText(MainActivity.this, "sent", Toast.LENGTH_LONG).show();
          }
    }
}

Thanks alot!

Nirav Dabhi
  • 341
  • 1
  • 7
  • 29