Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:56:55+00:00 2026-05-23T15:56:55+00:00

When i add more than one Fieldable to my Document i get a nullpointer

  • 0

When i add more than one Fieldable to my Document i get a nullpointer exception(without any exception description) when i try to add the document to the indexwriter.

i only changed the fieldable method called stringvalue, to return a string.

Is it not allowed to add more fieldables, or am i missing something ?

code that might be relevant

    File[] files = FILES_TO_INDEX_DIRECTORY.listFiles();
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_33);
    SimpleFSDirectory d = new SimpleFSDirectory(INDEX_DIRECTORY);
    IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_33, analyzer);
    IndexWriter indexWriter = new IndexWriter(d, iwc);

for (File file : files) {
        try
        {
        final String path = file.getCanonicalPath();
        final String name = file.getName();
        Fieldable field1 = new Fieldable()
        { removed  }

        Fieldable field2 = new Fieldable() {also removed}

        Document document = new Document();
        document.add(field1);
        document.add(field2);
        List<Fieldable> minliste = document.getFields();

        indexWriter.addDocument(document); //this is where it fails
        }

Fieldable :

Fieldable field1 = new Fieldable()
        {

            @Override
            public int getBinaryLength() {
                return 0;
            }

            @Override
            public int getBinaryOffset() {
                return 0;
            }

            @Override
            public byte[] getBinaryValue() {
                return null;
            }

            @Override
            public byte[] getBinaryValue(byte[] arg0) {

                return null;
            }

            @Override
            public float getBoost() {
                return 0;
            }

            @Override
            public boolean getOmitNorms() {
                return false;
            }

            @Override
            public boolean getOmitTermFreqAndPositions() {
                return false;
            }

            @Override
            public boolean isBinary() {
                return false;
            }

            @Override
            public boolean isIndexed() {
                return false;
            }

            @Override
            public boolean isLazy() {
                return false;
            }

            @Override
            public boolean isStoreOffsetWithTermVector() {
                return false;
            }

            @Override
            public boolean isStorePositionWithTermVector() {
                return false;
            }

            @Override
            public boolean isStored() {
                return false;
            }

            @Override
            public boolean isTermVectorStored() {
                return false;
            }

            @Override
            public boolean isTokenized() {
                return false;
            }

            @Override
            public String name() {
                //TODO
                return "path";
            }

            @Override
            public Reader readerValue() {
                return null;
            }

            @Override
            public void setBoost(float arg0) {
            }

            @Override
            public void setOmitNorms(boolean arg0) {
            }

            @Override
            public void setOmitTermFreqAndPositions(boolean arg0) {
            }

            @Override
            public String stringValue() {
                //TODO
                return path;
            }

            @Override
            public TokenStream tokenStreamValue() {
                return null;
            }                   
        };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:56:56+00:00Added an answer on May 23, 2026 at 3:56 pm

    You’re implementing your Fieldables from scratch. I suspect that the problem is hidden somewhere in your removed lines – maybe one of the implemented methods return null where it should return a real value.

    1. Try to add instances of Field instead and check if you still have the same error
    2. Use a debugger an add a breakpoint on NullPointerException, that should help finding the real cause of your problem.

    Now that you’ve added the implementation of your Fieldable I’m pretty sure that the NPE occurs because you return some null values in your implementation.

    A hot candidate is your implementation of readerValue() which returns null. JavaDoc explains, that the Reader that is returned by this method can be used at index time to generate index tokens. An indexing is what happens automatically when you add more then one Fieldable to a document.

    Give this a try:

    @Override
    public Reader readerValue() {
         return new StringReader(path);
    }
    

    Change your implementation and avoid return null unless the JavaDoc clearly says, that null is a legal return value.

    (and: even if Field is deprecated: use it for a test to see, if the problem is related to your Fieldables. If your code works with Field objects, then you know where to look)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to add a DataTable to more than one DataSet without calling DataTable.Copy().
Can any one help me to add more than one custom button to the
I know that I can add more than one project to a solution, but
Under a corporate apple developer account, is it possible to add more than one
Is it possible to add more than one x-axis to a plot in R?
Is it possible to add more than one instances of Static HTML: iframe tabs
I'm trying to add more than one countdown timer with the same date on
Is there a way or best practice to add more than one file (e.g.
Is it bad thing if I add more than one class for one object.
What happens on a Windows box once you add more drives than can fit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.