When I run the following code, it gives me a NullPointerException – How do I fix it?

后端 未结 3 1715
旧巷少年郎
旧巷少年郎 2021-01-16 05:36

I have the following class called sendAttachment.java, and also Piechart.java, and covertExcelTOCSV.java. I am reading in an els file converting it to csv and then having pi

相关标签:
3条回答
  • 2021-01-16 05:54

    The NullPointerException is being thrown in MimeUtility (line 226), rather than in the class you posted (though the problem likely originates in your code).

    It looks like it has something to do with encoding. Without being able to delve into the code it's hard to know. Some things you could experiment with...

    Try removing the parameter when you create the MimeMultipart:

    MimeMultipart multipart = new MimeMultipart();
    

    Try attaching a different kind of file, e.g. a text file. Perhaps it can't detect the appropriate encoding for a "jpg" file.

    0 讨论(0)
  • 2021-01-16 05:57

    Add this:

    fileDataSource.getOutputStream().close();
    

    after you have created and used FileDataSource object in your code. It should fix the problem (assuming fileDataSource is a FileDataSource object)

    check out : http://kenai.com/projects/javamail/sources/mercurial/content/mail/src/main/java/javax/mail/internet/MimeUtility.java?rev=469

    also if you are sending attachments in the multipart message first try zipping them in your code and then send . You had encoding issues in this problem , these encoders are friendly with .zips .

    0 讨论(0)
  • 2021-01-16 05:58

    This error occurs when the attached file cannot be read.

    0 讨论(0)
提交回复
热议问题