title: Java check if string is null or empty
body: <p>I got a few strings and I perform some checking before using the values on the charts. Here are my codes:</p>
  
  <pre><code>for (int j = 0; j &lt; shareByTypeList.size(); j++) {
              if (j == 0) {
                  facebookShare = shareByTypeList.get(j).getTotalShare();
              } else if (j == 1) {
                  googleplusShare = shareByTypeList.get(j).getTotalShare();
              } else {
                  twitterShare = shareByTypeList.get(j).getTotalShare();
              }
          }
  
          if (facebookShare != null &amp;&amp; !facebookShare.isEmpty()
                  &amp;&amp; twitterShare != null &amp;&amp; !twitterShare.isEmpty()
                  &amp;&amp; googleplusShare != null &amp;&amp; !googleplusShare.isEmpty()) {
              txtDisplayFacebook.setText(facebookShare);
              txtDisplayTwitter.setText(twitterShare);
              txtDisplayGooglePlus.setText(googleplusShare);
              totalShare = Integer.parseInt(facebookShare)
                      + Integer.parseInt(googleplusShare)
                      + Integer.parseInt(twitterShare);
              txtDisplayShareAmt.setText(String.valueOf(totalShare));
          }
  </code></pre>
  
  <p>I am checking if the string itself is null or empty before parse them into Integer. However, I am still getting NullPointerException at the if statement there. When I try to print out the facebookShare, it just appear empty at the console. Any ideas? </p>
  
  <p>Thanks in advance.</p>
  
  <p>The stack trace:</p>
  
  <pre><code>12-30 13:53:39.787: E/AndroidRuntime(1787): java.lang.NullPointerException
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at nyp.edu.eneighbourhood.EventDetailChart.onCreateView(EventDetailChart.java:191)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:495)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at nyp.edu.eneighbourhood.EventDetailMain$2.onTabSelected(EventDetailMain.java:42)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:512)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:893)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:502)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.view.View.performClick(View.java:3620)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.view.View$PerformClick.run(View.java:14292)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.os.Handler.handleCallback(Handler.java:605)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.os.Handler.dispatchMessage(Handler.java:92)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.os.Looper.loop(Looper.java:137)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at android.app.ActivityThread.main(ActivityThread.java:4512)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  12-30 13:53:39.787: E/AndroidRuntime(1787):     at dalvik.system.NativeStart.main(Native Method)
  12-30 13:53:49.334: I/Process(1787): Sending signal. PID: 1787 SIG: 9
  </code></pre>