I'm running Spinx voice recognition as a thread and want to pass the result to a bot method mirroring the same method in Main to pass text. However keep running into NullPointerExpection and can't reason it out or overcome it. Why does it work in Main but not in Reply class.   the text send button in Main is:  private void onSend(java.awt.event.ActionEvent evt) {                                 // display users message         txtHistory.setText(txtHistory.getText() + "\nYou: " + txtMessage.getText() + "\n");          //send the input to the bot and get bot response         String response = bot.send(txtMessage.getText());          //if the response is not empty show it         if (response.length() &gt; 0) {         addBotText(response);         }            //display new state message to continue         addBotText(bot.getMessage());             //clear the input message box        txtMessage.setText("");    }   In the Runnable (Threaded) Spinx Reply class i have a method to get the voice input and then show it as a string:      private void start_recognition(Result result) {              if (result != null) {                 String resultText = result.getBestFinalResultNoFiller();                 //send the message to the bot                 String response = bot.send(resultText);                 System.out.println("You said: " + resultText + '\n');             } else {                 System.out.println("I can't hear what you said.\n");         }    }   (With private Bot bot; commented above in both Main and Reply) When I comment the String response = bot.send(resultText); out all is well, but trying to invoke the bot.send method creates a nullPointerException. I realize I'm doing something incredibly stupid but can't figure it out. The Bot method is below. Any help greatly appreciated.  In Bot class the send method:     public String send(String message) {      String response = "";     State state = parser.getState(level);      // end of the tree     if (state.getKeywords().isEmpty()) {         this.level = "1";     }      // match the keyword with given message     Keyword match = parse(message, state.getKeywords());      // if no keyword is matched, display one of the invalid answers     if (match == null) {         response = parser.getInvalidAnswer();     } else {          // if match classname is provided, check to get the dynamic response         if (match.className.length() &gt; 0) {              // check for Weather dynamic response             if (match.className.equals("Weather")) {                 Weather weather = new Weather();                 response = weather.getResponse(match.arg);                 this.level = "1";             }             // check for News dynamic response             if (match.className.equals("News")) {                 News news = new News();                 response = news.getResponse(match.arg);                 this.level = "1";             }         } else {              // get the new state and return the new message             if (response.length() == 0) {                  this.level = match.target;                 state = parser.getState(level);                  // if it is end of the tree                 if (state.getKeywords().isEmpty()) {                     response = this.getMessage();                     this.level = "1";                  }             }         }     }     return response; }   All code for the conditional bot is credited to Majid Khosravi
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
Including null values in unpivoted column I am looking for a exact derivation of a relation between redshift $z$ and distance $d$.  What I know is the definition $$z=\frac{\lambda_{\text{observed}}}{\lambda_{\text{unshifted}}}-1=\sqrt{\frac{1+\frac{v}{c}}{1-\frac{v}{c}}}-1$$ and that the Hubble constant $H$ as a function of $z$ is: $$H^2=H_0^2\left(\Omega_m\left(1+z\right)^3+\Omega_{\Lambda}\right)$$  How can I use this to derive the distance? Multiple Installations and Understanding $PATH I have an older version of Git installed at:  /usr/bin/   I recently downloaded a newer version to:  /usr/local/bin   When I type:  which git   I get the location of the old version. I believe that this is just because /usr/bin/ appears before /usr/local/bin in my $PATH variable and so the older version of git is 'found' first.   To test this, I renamed the older version of git to "git_old". Now when I type:  which git   I get the location of the newer version, as expected. But when I type:  git --version   I get the following error:  -bash: /usr/bin/git: No such file or directory   I'm just wondering why my computer is going back to looking in the old location for Git? How can I combine hashes in Perl? What is the best way to combine both hashes into %hash1?  I always know that %hash2 and %hash1 always have unique keys.  I would also prefer a single line of code if possible.    $hash1{'1'} = 'red'; $hash1{'2'} = 'blue'; $hash2{'3'} = 'green'; $hash2{'4'} = 'yellow'; I unlocked the 'Files' button/icon from my unity launcher and now it disappearead and I cannot restore it or get it back I unlocked the 'Files' button for the Ubuntu file manager from the unity launcher and I cannot get it back.   When I run the file manager from the dash, the icon does not appear on the launcher like it does for all other applications while they are running. I wanted to have an empty launcher when no applications are running, and just have the icons of those I am actively using there.  Any idea why I don't see it in the launcher when its running or how to lock it back? Equal simple field extensions? I have a question about simple field extensions.  For a field $F$, if $[F(a):F]$ is odd, then why is $F(a)=F(a^2)$? How to place text above the figure/table How to place text above the rotated Figure (LANDSCAPE) in the same page. I tried but text automatically moved to the following page.  TEXT TEXT....   \begin{landscape} \begin{table}[] \centering \includegraphics[width=160mm]{figures2/comparation3.png} \caption{A comparison of Aloha protocols} \label{tab:ComparationAloha} \end{table} \end{landscape}     I added this code, but one part of table disappeared. I must have type TABLE since I need it for list of tables later.  \lipsum[11] \begin{table}[h!] \rotatebox{90}{\parbox{100mm}{ \includegraphics[width=160mm, rotate=90]{figures2/comparation3.png} \caption{A comparison of Aloha protocols} \label{tab:ComparationAloha}}} \end{table} \lipsum[12] When should I use exposure compensation? When should I use exposure compensation, rather than ISO, shutter speed or aperture? top command in cygwin? I am starting to use Cygwin(64) on my Windows 8 laptop, however, the top command is not recognized. I have read online that I need to get the procps package, but it is not available on the 'Cygwin Setup' package selections. How should I go about installing the procps package so that I can use top?  ps. for whatever reason ps and kill both work so I would think top would be included in whatever package allowed those guys to work, but there is no top command. My phone was just stolen an hour or so ago. Are there any options for tracking? I realize this is a long shot, but my phone was lost or stolen a few hours ago.  At the time it was stolen, I didn't have any specific applications installed to track it or wipe the data. So... my bad. I'm hoping the fact that I have a pattern lock will at least prevent anyone from accessing my data.  My question is, do I have any options for tracking or data wipe after the fact? (I'm more interested in tracking.)  Note: I have read similar questions, but unless I'm mistaken, they all address the question in terms of preparation before losing the phone. I'm asking about fallback options after losing the phone. Why does Stack Exchange use Imgur over Amazon S3 or Azure? What benefit does  offer over , , etc. for image hosting?   Is it the simplicity of integration? The cost model? What's better about using a "gateway"? Why does your reflection suddenly turn upside down while slowly walking away from a curved mirror? Many people should have realised, when looking into a concave curved mirror (or even a rather reflective spoon in that fact) at a close distance, you will see a slightly distorted reflection. But as you move further away, the image will suddenly become upside-down.  why is this? Is the universe fundamentally deterministic? In Avatar: The Last Airbender, Aang's eyes glow when he goes into the Avatar State. This seems to be the case with all Avatars, but Aang and the other airbending Avatars tattoos glow too.      Is there any reason for why airbending Avatars tattoos glow as well as their eyes? Possible to get type of an aliased type in c#? Type.GetType("System.String")   Is there a lookup for the aliases available somewhere?  Type.GetType("string")   returns null. I have noticed that while asking questions and scrolling to the bottom of the page, the right sidebar containing recent questions covers the footer partially. Also, a part of it goes beyond the browser's boundary. It may not be a big problem but it still doesn't look good.    This also happens on the  page CSV API for Java Can anyone recommend a simple API that will allow me to use read a CSV input file, do some simple transformations, and then write it.  A quick google has found  which looks promising.  I just wanted to check what others are using before I couple myself to this API. A get() like method for checking for Python attributes How run a .jar file with a double-click? passive Vs active or omission of 'which is' What is the part of speech of 'regarded' in the following?     "a quality of beauty and intensity of emotion regarded as characteristic of poems"    Why isn't it "... [which is] regarded ..."?  And in another case:      "a small lizard with wide feet, found especially in warm countries"     And also:      "Words used to describe writing or speech style"    In all these examples, why shouldn't the verbs be in their passive form (e.g. which is found, words that are used)?   I am a ESL learner and I am very confused by these usages!