Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Cast Exception

 
Robert Young
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am extracting the content from an email message. I am casting this into a string object. However, when it is a multipart message and it gets to the text/html content I get a class cast exception. Does anyone know what type of object is being returned since it is not a string.

I can't seem to find anything about it.

Below is the method:

private String extractContent(MimeMessage msg) throws MessagingException, IOException {
//extract content
StringBuffer sb = new StringBuffer(1000);
try{

if (msg.getContentType().indexOf("text/plain") != -1) {
//plain text message
sb.append((String) msg.getContent());
} else if (msg.getContentType().indexOf("text/html") != -1) {
sb.append((String) msg.getContent());
} else if (msg.getContentType().indexOf("multipart") != -1) {
Multipart mp = (Multipart) msg.getContent();
for (int i = 0; i < mp.getCount(); i++) {
Part part = mp.getBodyPart(i);
if (part.getContentType().indexOf("text/plain") != -1) {
sb.append((String) part.getContent());
} else if (part.getContentType().indexOf("text/html") != -1) {
sb.append((String) part.getContent());
}
}
}
}catch(UnsupportedEncodingException e){
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really wanna know you can do a

or something very similar to that basically you get the class and then it's name and you can tell exactly what you have.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually the detail message of the CCE will tell you. Not always though for some reason.

- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic