title: Nullpointer returned by function implemented in Locally bounded service in android
body: <p>I am writing a locally bound service in android.My application has two classes
  viz. Activity and a Service</p>
  
  <p>In my activity I have one TextView and one button.
  I am starting and binding the service in onCreate() method of the activity.
  When the button is getting clicked I want my TextView to be upadated with a String value returned from a fucntion written in the Service class</p>
  
  <p>But I am getting null as return value always.What may be the problem?</p>
  
  <p>I am giving my entire code here</p>
  
  <p>This is activity class</p>
  
  <pre><code> package com.tcs.cto.healthcare;
  
   import android.app.Activity;
   import android.content.ComponentName;
   import android.content.Context;
   import android.content.Intent;
   import android.content.ServiceConnection;
   import android.os.Bundle;
   import android.os.IBinder;
   import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.tcs.cto.healthcare.GlucoseDataService.LocalUSBSerialBinder;
  
  
  public class HealthcareCTOActivity extends Activity {
  
  Button getDataButton;
  TextView dataView;
  
  String TAG="HealthCareCTO";
  String glucoseData;
   GlucoseDataService myService;
      boolean isBound = false;
  
  
      private ServiceConnection myConnection = new ServiceConnection() {
  
          public void onServiceConnected(ComponentName className,
                  IBinder service) {
              LocalUSBSerialBinder binder = (LocalUSBSerialBinder) service;
              myService = binder.getService();
              isBound = true;
          }
  
          public void onServiceDisconnected(ComponentName arg0) {
              isBound = false;
          }
  
         };
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_healthcare_cto);
  
      getDataButton=(Button)findViewById(R.id.button1);
      dataView=(TextView)findViewById(R.id.glucoseDataView);
      Intent intent = new Intent(this, GlucoseDataService.class);
      startService(intent);
      bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
      Log.i(TAG,"Glucose Service Started");
  
      //getDataButton=(Button)findViewById(R.id.button1);
      //dataView=(TextView)findViewById(R.id.glucoseDataView);
      getDataButton.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View arg0) {
              Log.i(TAG,"Button clicked");
              try{
                  //glucoseData = myService.getGlucoseValueOverSerialPort();
                  String currentTime="XXX";
                  currentTime = myService.getCurrentTime();
                  //glucoseData = myService.getGlucoseValueOverSerialPort();
                  //Log.i(TAG,"glucoseData --&gt; "+glucoseData);
                  Log.i(TAG,"currentTume --&gt; "+currentTime);
                  dataView.setText(currentTime);
              }catch(Exception ex){
                  Log.i(TAG,"Button click exception");
                  ex.printStackTrace();
              }
  
  
          }
  
      });
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.activity_healthcare_cto, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my service class is as follows</p>
  
  <pre><code>package com.tcs.cto.healthcare;
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.Locale;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.Binder;
  import android.os.IBinder;
  import android.util.Log;
  
  public class GlucoseDataService extends Service {
  
  private final IBinder myBinder = new LocalUSBSerialBinder();
  String glucoseData="0000";
  String TAG="GlucoseService";
  @Override
  public IBinder onBind(Intent arg0) {
      // TODO Auto-generated method stub
      return null;
  }
  
  
   public String getGlucoseValueOverSerialPort(){
  
       int glucoseValue=120;
      glucoseData=String.valueOf(glucoseValue);
      return glucoseData;
   }
   public String getCurrentTime() {
       Log.i(TAG,"getCurrentTime");
          SimpleDateFormat dateformat = 
                   new SimpleDateFormat("HH:mm:ss MM/dd/yyyy", Locale.US);
          return (dateformat.format(new Date()));
      }
  
  public class LocalUSBSerialBinder extends Binder {
      GlucoseDataService getService() {
          return GlucoseDataService.this;
      }
  </code></pre>
  
  <p>};
  }</p>