First time XML user, what does this error mean?

phinoc

New Member
It's the first time I'm using XML in java and I would like some assistance with my code. I can't see where I'm wrong. thanks.What I am trying to do is understand the Spring Framework.Here is the code:\[code\]public class Student{ public Student(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } // VARIABLES DECLARATION private String name = null;}public class Controller{ public Controller(Student student) { this.student = student; } public void PrintName() { System.out.println(""+student.getName()); } public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } // VARIABLES DECLARATION private Student student;}public class LearnXML{ /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ApplicationContext factory = new ClassPathXmlApplicationContext("Student.xml"); Controller contr = (Controller) factory.getBean("application"); contr.PrintName(); } public void setController(Controller controller) { this.controller = controller; } private Controller controller;}\[/code\]My XML file:\[code\] <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="student" class="domain.Student"> <constructor-arg value="http://stackoverflow.com/questions/14031944/Ovidiu" /> </bean> <bean id="brain" class="controller.Controller"> <constructor-arg ref="student"/> </bean> <bean id="application" class="learnxml.LearnXML"> <property name="controller" ref="brain"/> </bean></beans>\[/code\]My errors:\[code\] Dec 25, 2012 5:34:02 PM org.springframework.context.support.AbstractApplicationContext prepareRefreshINFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@dd0099: startup date [Tue Dec 25 17:34:02 EET 2012]; root of context hierarchyDec 25, 2012 5:34:03 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitionsINFO: Loading XML bean definitions from class path resource [Student.xml]Dec 25, 2012 5:34:03 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletonsINFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5ceeb4a3: defining beans [student,brain,application]; root of factory hierarchyException in thread "main" java.lang.ClassCastException: learnxml.LearnXML cannot be cast to controller.Controller at learnxml.LearnXML.main(LearnXML.java:25)Java Result: 1\[/code\]
 
Back
Top