从语法上看 下面这段代码有什么问题吗?高手求救!!不大会用
报的错是这个:
Exception in thread "main" java.lang.NullPointerException
at com.query.Query1.ShowDetails(Query1.java:31)
at com.query.Query1.main(Query1.java:20)
package com.query;import java.io.DataInputStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
import edu.stanford.smi.protegex.owl.model.OWLIndividual;
import edu.stanford.smi.protegex.owl.model.RDFSLiteral;public class Query1 { JenaOWLModel model;
public static String queryString;
public ArrayList<String> al = new ArrayList<String>();
public static void main (String[] args) throws Exception {
Query1 q=new Query1();
q.setIndividualName("altar:Parmigianino_David");
System.out.println(q.ShowDetails(queryString));
} public String ShowDetails(String c) throws Exception
{
FileInputStream fstream2 = new FileInputStream("D://Program Files//Apache Software Foundation//Tomcat 5.5//webapps//ROOT//AltarPieces.owl");
DataInputStream in = new DataInputStream(fstream2);
model=ProtegeOWL.createJenaOWLModelFromInputStream(in); OWLIndividual ind2 = model.getOWLIndividual(c);
OWLDatatypeProperty longProp =model.getOWLDatatypeProperty("altar:hasPictureName");
RDFSLiteral retValLit = (RDFSLiteral)ind2.getPropertyValue(longProp);
return retValLit.getBrowserText();
} public void setIndividualName(String string1) {
this.queryString=string1;
}
public String getIndividualName(){
return this.queryString;
}
}
报的错是这个:
Exception in thread "main" java.lang.NullPointerException
at com.query.Query1.ShowDetails(Query1.java:31)
at com.query.Query1.main(Query1.java:20)
package com.query;import java.io.DataInputStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
import edu.stanford.smi.protegex.owl.model.OWLIndividual;
import edu.stanford.smi.protegex.owl.model.RDFSLiteral;public class Query1 { JenaOWLModel model;
public static String queryString;
public ArrayList<String> al = new ArrayList<String>();
public static void main (String[] args) throws Exception {
Query1 q=new Query1();
q.setIndividualName("altar:Parmigianino_David");
System.out.println(q.ShowDetails(queryString));
} public String ShowDetails(String c) throws Exception
{
FileInputStream fstream2 = new FileInputStream("D://Program Files//Apache Software Foundation//Tomcat 5.5//webapps//ROOT//AltarPieces.owl");
DataInputStream in = new DataInputStream(fstream2);
model=ProtegeOWL.createJenaOWLModelFromInputStream(in); OWLIndividual ind2 = model.getOWLIndividual(c);
OWLDatatypeProperty longProp =model.getOWLDatatypeProperty("altar:hasPictureName");
RDFSLiteral retValLit = (RDFSLiteral)ind2.getPropertyValue(longProp);
return retValLit.getBrowserText();
} public void setIndividualName(String string1) {
this.queryString=string1;
}
public String getIndividualName(){
return this.queryString;
}
}
31行是不是这行?是的话那就是ind2是null
this.queryString=string1;
}这个没必要, public 还是 static 的 , 没必要用set方法, 直接 用 Query1 .queryString = "abc"; 或者 String str = Query1 .queryString; 这样的方式使用就行了。
public String getIndividualName(){
return this.queryString;
}
这一块也不需要 用 this . 。 你直接 return queryString ; 就可以了不过这些都和语法正确没关, 你给的代码调用了许多自己的类, 所以没法调试 。