1

I'm trying to use Mime to transfer files between 2 Android devices. I have a sendFile() method which (surprisingly) sends the requested file.

Here's the code:

public void sendFile(File f) throws IOException {
    BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());
    String filename = 
        f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf("/") + 1);

    MultipartEntity multipartContent = new MultipartEntity();

    // send the file thorugh inputstream
    InputStreamBody isb = 
        new InputStreamBody(new FileInputStream(f), filename);

    multipartContent.addPart("sentFile", isb);

    multipartContent.writeTo(out);
    out.flush();
    out.close();
}

Now, I'm using the apache-mime4j-0.5.jar & httpmime-4.0-alpha3.jar files to support the "MultipartEntity" usage. Now, the jars are located in "libs" file in my android (app) project, and there are no importing issues (the project compiles...). Still, I'm getting this runtime error:

06-17 14:06:29.900: E/AndroidRuntime(22251): FATAL EXCEPTION: Thread-11
06-17 14:06:29.900: E/AndroidRuntime(22251): java.lang.NoSuchMethodError: org.apache.james.mime4j.message.Multipart.<init>
06-17 14:06:29.900: E/AndroidRuntime(22251): at org.apache.http.entity.mime.HttpMultipart.<init>  (HttpMultipart.java:64)
06-17 14:06:29.900: E/AndroidRuntime(22251): at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:76)
06-17 14:06:29.900: E/AndroidRuntime(22251): at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:99)
06-17 14:06:29.900: E/AndroidRuntime(22251): at com.cdp.controller.Connection.sendFile(Connection.java:71)
06-17 14:06:29.900: E/AndroidRuntime(22251): at com.cdp.controller.Controller.handleRequest(Controller.java:41)
06-17 14:06:29.900: E/AndroidRuntime(22251): at com.cdp.service.ServerService$SenderThread.run(ServerService.java:109)  

What could be the origin to this problem? How can I solve it? The app crashes while trying to instantiate the new MultipartEntity() object as seen in the code. I've gone trough many posts and nothing I tried works. I'll appreciate your help!

Thanks.

Felix Christy
  • 2,179
  • 1
  • 19
  • 32
Ido
  • 11
  • 1
  • Hi make sure you have the external library files in libs folder not in lib folder... If you have recently updated the android sdk this happens... also make sure you have linked the external library files in the build path – Dinash Jun 17 '12 at 14:32
  • Hi! Thanks! The jars are in "libs" folder and it is recognized by the android environment so I think it's not the problem. As for the build-path - it is configured as you suggested, and it still doesn't work. Do you have any other ideas? – Ido Jun 17 '12 at 14:41
  • Clean the project and run it once. Also try to restart the eclipse once if it doesn't work – Dinash Jun 17 '12 at 14:45
  • Thanks Dinash, but unfortunately it didn't help :( – Ido Jun 17 '12 at 15:54
  • @Ido ido did you find any solution on this then? – HarsH Jan 08 '14 at 18:30

0 Answers0