I don't get it. Where did you saw this in the Jena tutorial?

And do you understand that when you call in your main()

read(str, null);

that the second argument is always null, thus, the code will never go
into the if-clause?

> The read() method is given below: I used null reference after reading this
> tutorial of Jena which used it in main().
> *Since I have to create individual of name entered in text field and then
> button clicked, either I need OntClass in button handler or the string of
> text field in the read() method.*
>
> private static void read(String str, OntModel model)
>     {
>        //OntModel model = ModelFactory.createOntologyModel();
>
>         String ns="http://www.semanticweb.org/untitled-ontology-004/";;
>
>     if (model!= null ) {
>
>      OntClass user1 = model.getOntClass(ns + "User");
>     Individual janeSmith = user1.createIndividual(ns + str);
>
>
>        try {
>            String file="F://updated.owl";
>
>
>         FileWriter out=new FileWriter(file);
>
>              model.write( out, "RDF/XML-ABBREV" );
>         } catch (IOException ex) {
>             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
> null, ex);
>         }
>     }
>
> On Thu, Jul 14, 2016 at 1:38 AM, Lorenz B. <
> buehm...@informatik.uni-leipzig.de> wrote:
>
>> Andy already told you correctly that you call
>>
>> read(str, null) thus the second argument is null.
>>
>> Moreover, you did not show the read() method but only readOntology(),
>> thus, nobody knows what's going inside the read() method. But obviously,
>> some object is null and you call a method on that. I suggest to use a
>> Java debugger.
>>
>>> *As I also mentioned in the code: model.write(), it writes the rdf to
>>> console and load the GUI also.*
>>> *But when I enter text and press button ,it gives exception error:*
>>>
>>> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
>>> at javaapplication4.NewJFrame.read(NewJFrame.java:53)
>>> at javaapplication4.NewJFrame.jButton3ActionPerformed(NewJFrame.java:287)
>>> at javaapplication4.NewJFrame.access$100(NewJFrame.java:27)
>>> at javaapplication4.NewJFrame$2.actionPerformed(NewJFrame.java:135)
>>>
>>> On Wed, Jul 13, 2016 at 2:27 PM, Andy Seaborne <a...@apache.org> wrote:
>>>
>>>> This looks rather similar to ;
>>>>
>>>> http://stackoverflow.com/questions/38351713/creating-individual-in-jena
>>>>
>>>> I suggest local collaboration.
>>>>
>>>>
>>>> On 13/07/16 16:37, 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);
>>>>> }
>>>>> _____________________________________
>>>>>
>>>>> 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)
>>>>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

Reply via email to