title: Sentiment analysis with stanford nlp does not work
body: <p>I am trying to use stanford nlp to get the sentiment of a text:
  Here is my code:</p>
  
  <pre><code>import java.util.Properties;
  
  import edu.stanford.nlp.ling.CoreAnnotations;
  import edu.stanford.nlp.pipeline.Annotation;
  import edu.stanford.nlp.pipeline.StanfordCoreNLP;
  import edu.stanford.nlp.rnn.RNNCoreAnnotations;
  import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
  import edu.stanford.nlp.trees.Tree;
  import edu.stanford.nlp.util.CoreMap;
  
  public class SentimentAnalyzer {
  
      public static void main(String[] args) {
          findSentiment("");
      }
  
      public static void findSentiment(String line) {
          line = "I started taking the little pill about 6 years ago.";
          Properties props = new Properties();
          props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
          StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
          int mainSentiment = 0;
          if (line != null &amp;&amp; line.length() &gt; 0) {
              int longest = 0;
              Annotation annotation = pipeline.process(line);
              for (CoreMap sentence : annotation
                      .get(CoreAnnotations.SentencesAnnotation.class)) {
                  Tree tree = sentence
                          .get(SentimentCoreAnnotations.AnnotatedTree.class);
                  int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
                  String partText = sentence.toString();
                  if (partText.length() &gt; longest) {
                      mainSentiment = sentiment;
                      longest = partText.length();
                  }
  
              }
          }
          if (mainSentiment == 2 || mainSentiment &gt; 4 || mainSentiment &lt; 0) {
              System.out.println("Neutral " + line);
          }
          else{
          }
          /*
           * TweetWithSentiment tweetWithSentiment = new TweetWithSentiment(line,
           * toCss(mainSentiment)); return tweetWithSentiment;
           */
  
      }
  }
  </code></pre>
  
  <p>Also I use the instruction from this link:
  <a href="https://blog.openshift.com/day-20-stanford-corenlp-performing-sentiment-analysis-of-twitter-using-java/" rel="nofollow noreferrer">https://blog.openshift.com/day-20-stanford-corenlp-performing-sentiment-analysis-of-twitter-using-java/</a></p>
  
  <p>But I get the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at edu.stanford.nlp.rnn.RNNCoreAnnotations.getPredictedClass(RNNCoreAnnotations.java:58)
  at SentimentAnalyzer.findSentiment(SentimentAnalyzer.java:27)
  at SentimentAnalyzer.main(SentimentAnalyzer.java:14)
  </code></pre>
  
  <p>which point to this line:</p>
  
  <pre><code>    Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
  </code></pre>