2014-04-02 51 views
3

我正嘗試使用SimpleFTP將jpg圖像上傳到FTP服務器。Java.lang.NoClassDefFoundError:org.jibble.simpleftp.SimpleFTP在Android中上傳FTP中的圖像

以下是我的代碼:

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); 
} 

而且我得到了以下錯誤java.lang.NoClassDefFoundError

+0

http://stackoverflow.com/questions/11154252/how-to-solve-this-java-lang-noclassdeffounderror-org-apache-commons-io-output-d –

+0

@shylendra這些代碼是在java我需要在Android的解決方案! –

回答

0

已包含this罐子你的lib文件夾?

+0

OfCorse我在我的庫中添加了SimpleFTP.jar,結果也是一樣。 –

+0

然後嘗試清理您的項目並確保庫包含在您的構建路徑中。 (項目,屬性,Java構建路徑,添加jar,然後進入下一個選項卡(訂購和導出),並確保該庫已選中 – kospol

+0

嗯雅我已經在訂單和導出選項卡中檢查此Jar文件,然後也是同樣的錯誤!這是否有其他原因,如果你知道。 –

0

最後我得到了我的問題的解決方案。

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(); 
      } 
    } 
} 

非常感謝!