I think you need to pay attention to what td.next() returned; I
suspect in your case it returned false which means you cannot use any
of its APIs (.doc(), .freq(), etc.) after that.

Mike McCandless

http://blog.mikemccandless.com

On Thu, May 17, 2012 at 5:52 PM, Edward W. Rouse <ero...@comsquared.com> wrote:
> Lucene 3.6, java 1.6 I get the following:
>
> java.lang.NullPointerException at
> org.apache.lucene.index.DirectoryReader$MultiTermDocs.doc(DirectoryReader.ja
> va:1179)
>
> when running this code:
>
> IndexReader reader = this.getReader(index);
> int d = -1;
> TermDocs td = reader.termDocs(this.createIdTerm(id));
> if(td != null)
> {
>  td.next();
>  d = td.doc();
> }
>
> private Term createIdTerm(String id)
> {
>  return new Term(Constants.DEFAULT_ID_FIELD, id);
> }
>
> At the time this code runs I would expect that td would be null since there
> are no documents in the index that match the term, but that is not the case.
> Instead I get the NPE when trying td.doc(). I can wrap the code in a
> try/catch for that line, but I think there must be a better way to determine
> if I got any matches for a Term.
>
> Edward W. Rouse
> Comsquared System, Inc.
> 770-734-5301
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to