Yes you are right sir, it is a project based assignment but stuck in the first portion/part of creating individuals based on user entered string. I initialized the OntModel in the button handler as:
jButton1ActionPerformed(java.awt.event.ActionEvent evt) { OntModel model=ModelFactory.createOntologyModel(); String str=jTextField2.getText(); read1(str, model); null pointer exception disappear and it gives error of : line 1 co*lumn 1): Content is not allowed in prolog.* I think this is due to some white spaces but it usually happens when there are some xml tags. What type of white space will be there in a jena code? On Thu, Jul 14, 2016 at 11:24 PM, Lorenz B. < buehm...@informatik.uni-leipzig.de> wrote: > OntModel is the in-memory knowledge base.That's where you create the > individual. By the way, some of your class mates asked similar things on > Stackoverflow, so it looks like you're doing some assignments. > I also don't see the problem. A user enters a String and you use this to > create the individual. That are more or less Java basics. > > > I am sorry but I thought if Ontclass can be passed as null, so shall be > > OntModel. My sole purpose is to pass the string entered by user to the > > read() which can be used create individuals. > > > > On Thu, Jul 14, 2016 at 5:03 AM, Lorenz B. < > > buehm...@informatik.uni-leipzig.de> wrote: > > > >> In which the second argument is the class and not the model as in your > >> code. It looks like you did mostly copy and paste without understanding > >> the code. > >> > >> In your case the model is ALWAYS null, do you understand that? > >>> I have read it here: > >>> http://tutorial-academy.com/category/java/ > >>> > >>> He used null argument in the main() method: > >>> > >>> public static void main(String[] args) > >>> { > >>> // create OntModel > >>> OntModel model = ModelFactory.createOntologyModel(); > >>> // read camera ontology > >>> readOntology( "./ontology/camera.owl", model ); > >>> // start traverse > >>> traverseStart( model, null ); > >>> } > >>> > >>> On Thu, Jul 14, 2016 at 4:09 AM, Lorenz B. < > >>> buehm...@informatik.uni-leipzig.de> wrote: > >>> > >>>> 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 > >>>> > >>>> > >> -- > >> 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 > >