Android application stopped unexpectedly
<p>I was trying to listen the accelerometer sensor on a mapview only when the start button is pressed and the stop button is not. </p>

<p>The application Starea Drumurilor has stopped unexpectedly.Please try again .
Can you tell me what is wrong in this?</p>

<p>This is may main program:
    public class RoutePath extends MapActivity  {
    /** Called when the activity is first created. */</p>

<pre><code>MapView mapView;
MyLocationOverlay compass;
List&lt;Overlay&gt; ToatemapOverlays;
Button bStart;
Button bStop;
TextView t1;
List&lt;Overlay&gt; listOfOverlays;
SensorManager sensorManager = null;
Sensor myAcc;
SensorManager mSensorManager;
MySensorListener listener;
int count = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MapView mapView = (MapView) findViewById(R.id.mapview);
 mapView.setBuiltInZoomControls(true);
 mapView.displayZoomControls(true);

 //__________________________
 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
 List&lt;Sensor&gt; sensorList = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
 myAcc = sensorList.get(0);

 //BUTOANE________________________
//set up the button sound

    final MediaPlayer mpbStart=MediaPlayer.create(this,R.raw.button1);
    t1=(TextView)findViewById(R.id.TextRecording);
    t1.setVisibility(View.INVISIBLE);
    bStart =(Button) findViewById(R.id.Butonstart);

    bStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            // Register Listener
            mSensorManager.registerListener(listener = new MySensorListener(count), myAcc , SensorManager.SENSOR_DELAY_UI);
            //reading.setText("Stop");

            //startActivity(new Intent("com.stareadrumurilor.google.STARTACTIVITATE"));
            bStart.setVisibility(View.INVISIBLE);
            t1.setVisibility(View.VISIBLE);
            mpbStart.start();
        }
    });


  //set up the button sound
    final MediaPlayer mpbStop=MediaPlayer.create(this,R.raw.button2);

    bStop =(Button) findViewById(R.id.ButonStop);

    bStop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //unregister listener
            mSensorManager.unregisterListener(listener, myAcc);
            //MySensorListener.onStop();
            //startActivity(new Intent("com.stareadrumurilor.google.STARTACTIVITATE"));
            bStart.setVisibility(View.VISIBLE);
            t1.setVisibility(View.INVISIBLE);
            mpbStop.start();
        }
    });    
</code></pre>

<p>AND THIS IS THE 
MySenzorListener Class</p>

<pre><code>    public class MySensorListener implements SensorEventListener{

   // String comma = new String(",");
    //private PrintWriter mCurrentFile;
    private Float accelXValue;
    private Float accelYValue;
    private Float accelZValue;
    private int i;
    private int[] vectorstare;
    private float ok;

    public MySensorListener(int count){
        //Creating a file to print the data into

        //String nameStr = new String("/sdcard/data" + count + ".csv");
       // File outputFile = new File(nameStr);
       // mCurrentFile = null;
       // try {
        //  mCurrentFile = new PrintWriter(new FileOutputStream(outputFile));
        //} catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
       // }
         i=0; 
         // Initialize accelerometer elements
         accelXValue=(float) 0.00;
         accelYValue=(float) 0.00;
         accelZValue=(float) 0.00;




    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // TODO Auto-generated method stub

    }


    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {

       // StringBuffer buff = new StringBuffer();
       // buff.append(String.valueOf(event.timestamp));
       // buff.append(comma);
       // buff.append(String.valueOf(event.values[0]));
       // buff.append(comma);
       // buff.append(String.valueOf(event.values[1]));
       // buff.append(comma);
       // buff.append(String.valueOf(event.values[2]));
       // mCurrentFile.println(buff.toString());
        //if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) 
            accelXValue=sensorEvent.values[0];
            accelYValue=sensorEvent.values[1];
            accelZValue=sensorEvent.values[2]; 
        //Incepem verificarile
        //pe axa X
        if ((accelXValue&gt;4)||(accelXValue&lt;-4))
        {vectorstare[i]=4;
        i++; }
        if (((accelXValue&gt;3)&amp;&amp;(accelXValue&lt;=4))||((accelXValue&lt;-3)&amp;&amp;(accelXValue&gt;=-4)))
        {vectorstare[i]=3;
        i++;}
        if(((accelXValue&gt;2)&amp;&amp;(accelXValue&lt;=3))||((accelXValue&lt;-2)&amp;&amp;(accelXValue&gt;=-3)))
        {vectorstare[i]=2;
        i++;}
        if(((accelXValue&gt;1)&amp;&amp;(accelXValue&lt;=2))||((accelXValue&lt;-1)&amp;&amp;(accelXValue&gt;=-2)))
        {vectorstare[i]=1;
        i++;}
        if(((accelXValue&gt;=0)&amp;&amp;(accelXValue&lt;=1))||((accelXValue&lt;=0)&amp;&amp;(accelXValue&gt;=-1)))
        {vectorstare[i]=0;
        i++;}
        //pe axa y
        if ((accelYValue&gt;4)||(accelYValue&lt;-4))
        {vectorstare[i]=4;
        i++; }
        if (((accelYValue&gt;3)&amp;&amp;(accelYValue&lt;=4))||((accelYValue&lt;-3)&amp;&amp;(accelYValue&gt;=-4)))
        {vectorstare[i]=3;
        i++;}
        if(((accelYValue&gt;2)&amp;&amp;(accelYValue&lt;=3))||((accelYValue&lt;-2)&amp;&amp;(accelYValue&gt;=-3)))
        {vectorstare[i]=2;
        i++;}
        if(((accelYValue&gt;1)&amp;&amp;(accelYValue&lt;=2))||((accelYValue&lt;-1)&amp;&amp;(accelYValue&gt;=-2)))
        {vectorstare[i]=1;
        i++;}
        if(((accelYValue&gt;=0)&amp;&amp;(accelYValue&lt;=1))||((accelYValue&lt;=0)&amp;&amp;(accelYValue&gt;=-1)))
        {vectorstare[i]=0;
        i++;}
        //pe axa z
        if ((accelZValue&gt;4)||(accelZValue&lt;-4))
        {vectorstare[i]=4;
        i++; }
        if (((accelZValue&gt;3)&amp;&amp;(accelZValue&lt;=4))||((accelZValue&lt;-3)&amp;&amp;(accelZValue&gt;=-4)))
        {vectorstare[i]=3;
        i++;}
        if(((accelZValue&gt;2)&amp;&amp;(accelZValue&lt;=3))||((accelZValue&lt;-2)&amp;&amp;(accelZValue&gt;=-3)))
        {vectorstare[i]=2;
        i++;}
        if(((accelZValue&gt;1)&amp;&amp;(accelZValue&lt;=2))||((accelZValue&lt;-1)&amp;&amp;(accelZValue&gt;=-2)))
        {vectorstare[i]=1;
        i++;}
        if(((accelZValue&gt;=0)&amp;&amp;(accelZValue&lt;=1))||((accelZValue&lt;=0)&amp;&amp;(accelZValue&gt;=-1)))
        {vectorstare[i]=0;
        i++;}
         }

    public float inchide(){ 
        int suma=0;
        for(int j=0;j&lt;i;j++)
            suma=suma+vectorstare[j];
        ok=Math.round(suma/i); 
        return ok;}


    protected void onStop() {
    // Unregister the listener
   // sensorManager.unregisterListener(this);

    inchide();
    }



}
</code></pre>
