null pointer exception in RelationshipFinder

Help
azalea99
2005-02-22
2013-04-29
  • azalea99

    azalea99 - 2005-02-22

    Hi, there,

    Got a problem with relationshipfinder, anyone can help?

    try to find Hypernym relationship between synsets of two words. when there is no relationship between them, the method caused null pointer exception at run time. my code is as the following:

    RelationshipFinder finder = RelationshipFinder.getInstance
    ();
    RelationshipList list = finder.findRelationships
    (synsetSource,synsetTarget,PointerType.HYPERNYM);

    synsetSource and synsetTarget are type of Synset
    I'v tested all arguments object in the method that they are not null.

    So when there is no relationships between two synsets, what wil be returned by the method findRelationship? or any other code could be used to find Hypernym relationship between two word?

    Thanks for any respons.

     
    • azalea99

      azalea99 - 2005-02-28

      Has anyone experienced  RelationshipFinder.findrelationship before. any response would be greate!

       
    • Marco

      Marco - 2006-01-28

      I have the same problem. Any one can hel us?

       
    • Marco

      Marco - 2006-01-28

      This is my problem. I use this my code:

      public class route {
         private static String propsFile = "file_properties.xml";   
         private IndexWord retWord;

         public route() {
            try {
               JWNL.initialize(new FileInputStream(propsFile));
            } catch (Exception ex) {
               ex.printStackTrace();
           System.exit(-1);
            }
         }

            public int[] retroute(IndexWord source, IndexWord target) throws JWNLException {
            int[] ret= new int[2];

            RelationshipList list = RelationshipFinder.getInstance().findRelationships(source.getSense(1), target.getSense(1), PointerType.HYPERNYM);
            System.out.println("Hypernym relationship between \"" + source.getLemma() + "\" and \"" + target.getLemma() + "\":");
            for (Iterator itr = list.iterator(); itr.hasNext();) {
               ((Relationship) itr.next()).getNodeList().print();
            }
            System.out.println("Common Parent Index: " + ((AsymmetricRelationship) list.get(0)).getCommonParentIndex());
            System.out.println("Depth: " + ((Relationship) list.get(0)).getDepth());
            ret[0]=(((AsymmetricRelationship) list.get(0)).getCommonParentIndex());
            ret[1]=((Relationship) list.get(0)).getDepth();
            return(ret);
         }

      }

      If I use "sorce"="dog" and "target"="canine" or "cat" all work good, but if I use the words "dog" and "thing" return error like this:

      Hypernym relationship between "dog" and "thing":
      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
              at java.util.ArrayList.RangeCheck(Unknown Source)
              at java.util.ArrayList.get(Unknown Source)
              at net.didion.jwnl.util.TypeCheckingList.get(TypeCheckingList.java:212)
              at provawordnet.demonstrateAsymmetricRelationshipOperation(provawordnet.
      java:122)
              at provawordnet.go(provawordnet.java:73)
              at provawordnet.main(provawordnet.java:34)

      Someone can help me?

       
    • deedee

      deedee - 2006-02-04

      Hi,
      ...yes, have had this problem. I'm pretty sure that all you need to do is check that the 'List' is not empty (it's not a great 'solution' but it's the only way that I stopped the 'Null Pointer Exception')

       

Log in to post a comment.