Hi Lorenz, I am sorry but with much regards, you discussed here the problem, not the solution :) :)
I know this if there is no value, there must be Null exception, but can you suggest me a way where we dodge the compiler and it skip the lines when there is no value. I know this is more a Java problem, but any help I will appreciate. Regards On Tue, Jan 17, 2017 at 4:20 PM, Lorenz B. < [email protected]> wrote: > no no no, I told you that the method getPropertyValue(p) can return NULL > if there is no such value for the given property p > > That means what for your line > > RDFNode physicsBestCat=indiv.getPropertyValue(bestcat); > > ? > > Right, physicsBestCat can be NULL. > > That means what for your line > > Literal l1=physicsBestCat.asLiteral(); > > ? > > Right, asLiteral() must not be called if physicsBestCat is NULL. > > > I mean Lorenz, is there any way, if there is no value, it do nothing (do > > not give exception) and if there is value, it should simply give us the > > value. > > > > if (l1!=null) supposed to work. :) > > > > Is it possible if we use something > > > > if (li==null) > > break; > > > > And we should get out of this snippet? > > > > Regards > > > > On Tue, Jan 17, 2017 at 4:10 PM, Lorenz B. < > > [email protected]> wrote: > > > >> ??? > >> > >> if there is no such value you can't get the value, I do not see the > problem > >>> Hello Lorenz, thanks. > >>> > >>> Is there any way (alternative) to get this value as I need it further > in > >> my > >>> operation? > >>> > >>> Regards > >>> > >>> On Tue, Jan 17, 2017 at 4:03 PM, Lorenz B. < > >>> [email protected]> wrote: > >>> > >>>>> Hello Lorenz, believe me I have tried this before I write my problem > >> here > >>>>> in the forum but the problem persists. I also tried if s1!=null. . > >>>>> > >>>>> RDFNode physicsBestCat=indiv.getPropertyValue(bestcat); > >>>> But then the NullPointerException already occurs here. > >>>> > >>>> getPropertyValue can return NULL if there is no such value, that's > also > >>>> explained in the Javadoc > >>>>> Literal l1=physicsBestCat.asLiteral(); > >>>> You can't do it if physicsBestCat can be NULL > >>>>> if (l1!=null){ > >>>>> String s1=l1.toString(); > >>>>> > >>>>> if (s1=="Physics"){ > >>>>> }} > >>>>> > >>>>> Regards > >>>>> > >>>>> On Tue, Jan 17, 2017 at 3:48 PM, Lorenz B. < > >>>>> [email protected]> wrote: > >>>>> > >>>>>> Sorry, but the answer is too obvious, especially for a student in > >>>>>> computer science. > >>>>>> > >>>>>> What about checking if the literal is NULL before calling > toString()? > >>>>>> > >>>>>>> Hello, I asked about this rule few days ago. > >>>>>>> String rule ="[rule1: ( ?x http://www.semanticweb.org/t/o > >>>>>>> ntologies/2016/7/myOWL#Physics_Preferred_Category ?cat1 )" + > >>>>>>> "( ?x http://www.semanticweb.org/t/ontologies/2016/7/myOWL#Chem_ > Pr > >>>>>>> eferred_Category ?cat2 )" + > >>>>>>> // "( ?x http://www.semanticweb.org/t/o > >>>>>>> ntologies/2016/7/myOWL#Geo_Preferred_Category ?cat3 )" + > >>>>>>> // "greaterThan(?cat1,?cat2), greaterThan(?cat1,?cat3)" > >>>>>>> + " -> (?x http://www.semanticweb.org/t/ > >>>>>>> ontologies/2016/7/myOWL#BestCategory > http://www.semanticweb.org/t/ > >>>>>>> ontologies/2016/7/myOWL#BestCategory#Physics )]"; > >>>>>>> > >>>>>>> The BestCategory is saved but as you know a user will select all > the > >>>>>> three > >>>>>>> categories in the quiz, then the rule will execute, otherwise the > >> user > >>>>>> the > >>>>>>> user will have not the property BestCategory. > >>>>>>> > >>>>>>> When I want to extract the value of BestCategory for some > operation, > >>>> for > >>>>>>> first time users to the quiz, it gives me Null Pointer Exception, > and > >>>>>>> rightly so because the user has no value of BestCategory. > >>>>>>> > >>>>>>> RDFNode physicsBestCat=indiv.getPropertyValue(bestcat); > >>>>>>> Literal l1=physicsBestCat.asLiteral(); > >>>>>>> > >>>>>>> //*here I think is the exception is* > >>>>>>> String s1=l1.toString(); > >>>>>>> > >>>>>>> if (s1=="Physics"){ > >>>>>>> } > >>>>>>> > >>>>>>> How should I handle this problem please? > >>>>>>> > >>>>>>> Much regards > >>>>>>> > >>>>>> -- > >>>>>> 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 > >
