> 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