Search code examples
javasvmweka

Does anyone know how to add a value to org.w3c.dom.Element to instantiate both MiningSchema and SupportVectorMachineModel?


I have a github repo here that has all of my code in it. The snippet that gives me a null pointer is in Model, nullpointer at Model:32. I'm still not completely sure what to do here. I have everything else ready to work, this is the one thing giving me an issue. The code snippet is as follows:

 private SupportVectorMachine svm = new SupportVectorMachine();
 private SupportVectors supportVectors = new SupportVectors();
 private SupportVectorMachineModel svmModel;
 private MiningSchema schema;
 private ClassLoader loader = new ClassLoader();

 private Element element;

public  void create(Instances instances) throws IOException, SAXException
{
    assert instances!=null;
        DocumentBuilder builder = null;
        element = (Element) builder.parse(instances.toString());
        try
        {
            schema = new MiningSchema(element, instances, schema.getTransformationDictionary());
            svmModel = new SupportVectorMachineModel(element, instances, schema);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

Solution

  •  private Element element;
     Document doc;
    
     public  void create(Instances instances) throws IOException, SAXException, ParserConfigurationException {
         assert instances!=null;
         DocumentBuilderFactory documentBuilderFactory = new DocumentBuilderFactoryImpl();
         DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
         assert builder != null;
         doc = builder.parse(instances.toString());
             element = (Element) doc;    
    

    I created a new Document from the instances, then cast it to an element.