Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

warning:unchecked cast

843793Nov 26 2007 — edited Nov 27 2007
I am one of the many that have this compiler problem. When i compile this program( i want to check how it works).

import generated.*;
import javax.xml.bind.*;

import java.io.File;
import java.util.List;

public class JAXBUnMarshaller {
  public void unMarshall(File xmlDocument) {
    try {
 JAXBContext jaxbContext = JAXBContext.newInstance("generated");
 Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();

 JAXBElement<CatalogType> catalogElement =     (JAXBElement<CatalogType>)
 unMarshaller.unmarshal(xmlDocument);
 CatalogType catalog=catalogElement.getValue();

	System.out.println("Section: " + catalog.getSection());
	System.out.println("Publisher: " + catalog.getPublisher());
	List<JournalType> journalList = catalog.getJournal();
	for (int i = 0; i < journalList.size(); i++) {
		JournalType journal = (JournalType) journalList.get(i);
		List<ArticleType> articleList = journal.getArticle();
		  for (int j = 0; j < articleList.size(); j++) {
		    ArticleType article = (ArticleType)articleList.get(j);

System.out.println("Article Date: " + article.getDate());
System.out.println("Level: " + article.getLevel());
System.out.println("Title: " + article.getTitle());
System.out.println("Author: " + article.getAuthor());
				}
			}
		} 
catch (JAXBException e) {
System.out.println(e.toString());
		}
	}

	public static void main(String[] argv) {
		File xmlDocument = new File("catalog.xml");
		JAXBUnMarshaller jaxbUnmarshaller = new JAXBUnMarshaller();
		jaxbUnmarshaller.unMarshall(xmlDocument);
	}
}
IT responds to me
_JAXBUnMarshaller.java:15:warning: [unchecked] unchecked cast_
found: java.lang.Object
required:javax.xml.bind.JAXBElement(generated.CatalogType)

Can anyone help?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 25 2007
Added on Nov 26 2007
1 comment
570 views