Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException on first thread
    primarykey
    data
    text
    <p>EDIT:</p> <p>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. :)</p> <p>I am writing a small program and a <code>NullPointerException</code> drives me crazy. I have two classes: <code>SystemDir</code> and <code>Search</code>. The first one is just an encapsulation of initial directory and a search lemma. The <code>Search</code> 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 </p> <pre><code>Exception in thread "Thread-0" java.lang.NullPointerException at Search.searchFiles(Search.java:59) at Search.&lt;init&gt;(Search.java:53) at SystemDir.&lt;init&gt;(SystemDir.java:61) at Search$1.run(Search.java:45) at java.lang.Thread.run(Thread.java:679) </code></pre> <p>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?</p> <pre><code>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&lt;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&lt;subFiles.length;i++) { t.start(); if(subFiles[i].contains(lemma)) { System.out.println(subFiles[i]); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload