• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class Cast Exception

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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){
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually the detail message of the CCE will tell you. Not always though for some reason.

- Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic