title: I get the error as "missing an @XmlRootElement annotation" while trying to marshall an object into xml file using JAXB
body: <p>I am someone who has just started to use JAXB,All I need  it for is write an object into xml and read it back into java at some point</p>
  
  <p>Here is my class:</p>
  
  <pre><code>public class VSM implements  java.io.Externalizable 
  {
  
       ArrayList&lt;String&gt; termList;                    //Term Dictionary
       ArrayList&lt;String&gt; queryTermList;               //Query list
       ArrayList&lt;ArrayList&lt;Doc&gt;&gt; docLists;                    
       ArrayList&lt;ArrayList&lt;Doc&gt;&gt; queryDocLists;
       double[] docLength;                               //Denominator for doc linearization      
       double queryLength;                               //Denominator for query lineriazation
  
  
       HashMap&lt;String, Double&gt; queryDocLenght;        //Vector for holding noramiliase queries  
       HashMap&lt;String, Double&gt; queryDoc;
       String Docs[];                          //List of file names 
  
       Double scoreCap=0.04;                          //Score cap to reduce the effect of stop words
  
       public static String fileName = "indexedFiles.txt";
       private static final long serialVersionUID = 7863262235394607247L;
  public VSM()
  {
  //Some constructor code
  }
  }
  </code></pre>
  
  <p>Here is the method I use to construct the XML file </p>
  
  <pre><code>public void writeXML(VSM vsm)
        {
            try {
  
                  File file = new File("IndexXmlfile.xml");
                  //JAXBElement&lt;VSM&gt; jaxbWrappedHeader =  objectFactory.createHeader(obj);
  
                  JAXBContext jaxbContext = JAXBContext.newInstance(VSM.class);
                  Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
  
                  // output pretty printed
                  jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
                  jaxbMarshaller.marshal(new JAXBElement&lt;VSM&gt;(new QName("uri","local"), VSM.class, vsm), System.out);
  
                  jaxbMarshaller.marshal(vsm, file);
                  jaxbMarshaller.marshal(vsm, System.out);
  
                    } catch (JAXBException e) {
                  e.printStackTrace();
                    }
  
        }
  </code></pre>
  
  <p>Altough WHen I try to run the code I get the error as :</p>
  
  <pre><code>javax.xml.bind.MarshalException
   - with linked exception:
  [com.sun.istack.SAXException2: unable to marshal type "KPT.VSM" as an element because it is missing an @XmlRootElement annotation]
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
      at KPT.VSM.writeXML(VSM.java:477)
      at KPT.VSM.main(VSM.java:511)
  Caused by: com.sun.istack.SAXException2: unable to marshal type "KPT.VSM" as an element because it is missing an @XmlRootElement annotation
      at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:249)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:339)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
      ... 4 more
  </code></pre>
  
  <p>I dont understand JABX  and all it methods fully yet ,so its kind of difficult for me understand this error,I tried googling a little and found a lot of people get this error, but still find it difficult to understand the problem the solution here..</p>