我一直在尝试加载我在Protégé中制作的OWL文件。我将OWL API 3.4.3导入到我的项目中,并将sample.owl
文件传递给raw文件夹,但是当我尝试加载OWL文件时,它不起作用。没有错误,但我只是收到此消息
遗憾的是,sampleproject已停止
以下是我正在使用的代码部分。当我在标准Java环境中尝试代码时,它没有问题。
OWLOntology localOntology = null;
int rID = resources.getIdentifier("com.example.cammclient1:raw/"+"sample", null, null);
InputStream input = resources.openRawResource(rID);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
ontology = manager.loadOntologyFromOntologyDocument(input);
try {
for (OWLClass cls : localOntology.getClassesInSignature()) {
Log.d("class in the ontology", ((CharSequence) cls).toString());
}
TV1.setText("reading classes...............");
}
catch (Exception e) {
TV1.setText("Not successfull");
}
答案 0 :(得分:0)
您正在将OWLClass
个实例投射到CharSequence
,然后在其上调用toString()
。
这将导致抛出ClassCastException
- OWLClass不是字符串。
只需使用cls.toString()
,您就会得到相同的结果。
你也吞下了catch区块中的异常。这对诊断问题没有帮助,因为它只是在没有提供更多信息的情况下说“不成功”来隐藏信息。