我有一个github存储库here,其中包含我的所有代码。为我提供空指针的代码段在Model中,在Model:32处为nullpointer。我仍然不太确定该怎么做。 我已经准备好其他所有工作,这是给我一个问题的一件事。代码段如下:
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();
}
}
答案 0 :(得分:0)
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;
我从实例创建了一个新Document,然后将其转换为元素。