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 8564251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:09:18+00:00 2026-06-11T17:09:18+00:00

EDIT: After making all the changes you suggested, the problem remained. The debugger said

  • 0

EDIT:

After making all the changes you suggested, the problem remained. The debugger said the lemma variable was null, but the fixes I applied didn’t make things better. So, due to deadline issues, I decided to approach the problem from another view. Thank you all for your help. 🙂

I am writing a small program and a NullPointerException drives me crazy. I have two classes: SystemDir and Search. The first one is just an encapsulation of initial directory and a search lemma. The Search class is shown below. Briefly, I want one thread to search the first level directory and the other one to expand the subdirectories. That’s where I get the exception. The exception string is

Exception in thread "Thread-0" java.lang.NullPointerException
at Search.searchFiles(Search.java:59)
at Search.<init>(Search.java:53)
at SystemDir.<init>(SystemDir.java:61)
at Search$1.run(Search.java:45)
at java.lang.Thread.run(Thread.java:679)

Where the 3 points are t.start() inside the final loop, searchFiles method call, some lines above and the new SystemDir call in the run method. Can you help me please?

public class Search {
   private Thread t;

   public Search(String[] subFiles, final String[] subDir, final String lemma) {
       t = new Thread(new Runnable() {
           @Override
           public void run() {
               for(int i=0;i<subDir.length;i++) {
                   try {
                       System.out.println(subDir[i]);
                       new SystemDir(subDir[i], lemma);
                   }
                   catch (NoDirectoryException ex) {
                       Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex);
                   }
               }
           }
       });

       searchFiles(subFiles,lemma); 
    }

    private void searchFiles(String[] subFiles, String lemma) {
       for(int i=0;i<subFiles.length;i++) {
            t.start();
            if(subFiles[i].contains(lemma)) {
                System.out.println(subFiles[i]);                    
            }
        }
    }
}
  • 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-06-11T17:09:20+00:00Added an answer on June 11, 2026 at 5:09 pm

    As a rule, never start a thread from a constructor. It can create all sorts of issues, which may be responsible for the exception you get.

    Create the thread like you do in your constructor, make searchFiles public and call that method from the client code, not from the constructor.

    Apart from that, have you checked that:

    • subFiles is not null
    • none of the subFiles[i] is null
    • lemma is not null

    (add println statements if necessary)

    and as pointed out by @Gray, you can’t start a thread more than once.

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

Sidebar

Related Questions

EDIT 1 I apologize but after reading the 2 suggested articles I still don't
Possible Duplicate: Saving changes after table edit in SQL Server Management Studio I need
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
[EDIT] I am changing this to more concisely explain what my problem was, after
Hi there I developed an applicaiton that uses SQLlite database but after making setup
EDIT: I'm sorry for making this thread as I've figured out the problem. Here's
EDIT: Ok, so i figured out how to remedy my original problem, but i'm
FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
Edit note: After a seemingly enourmous amount of bad feedback MS got from their
I'm trying to immediately set a row to Edit mode after it is created.

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.