On 13/07/16 16:58, kumar rohit wrote:
Hi
I have the following code in which I want to create an instance/individual
of the class Student. The student name is entered in a text box (in a
button even handler). But it gives exception.
_________________________________________
public class NewJFrame extends javax.swing.JFrame {
public static void readOntology( String file, OntModel model )
{
InputStream in = null;
try
{
in = new FileInputStream( file );
model.read(in, "RDF/XML");
in.close();
} catch (IOException e)
{
e.printStackTrace();
}
My main() is the following.
________________________________
public static void main(String args[]) {
OntModel model = ModelFactory.createOntologyModel();
String file="D://std.owl";
readOntology(file , model );
_______________________________________
Button handler to get student name from text box is:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String str=jTextField1.getText();
read(str, null);
}
And read() is following
_______________________________
private static void read(String str, OntModel model)
{
String ns="http://www.semanticweb.org/untitled-ontology-112/";
OntClass univer = model.createClass(ns + str);
if you pass null as model, then indeed it will NPE.
try {
FileWriter out=new FileWriter("D://std.owl");
model.write( out, "RDF/XML-ABBREV" );
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
__________________________
WARN [main] (RDFDefaultErrorHandler.java:36) - unknown-source: {W136}
Relative URIs are not permitted in RDF: specifically <RDF/XML>
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javaapplication4.NewJFrame.read(NewJFrame.java:50)
at javaapplication4.NewJFrame.jButton2ActionPerformed(NewJFrame.java:266)
at javaapplication4.NewJFrame.access$000(NewJFrame.java:27)
at javaapplication4.NewJFrame$1.actionPerformed(NewJFrame.java:103)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)