Hello, I'm completely new to android development, and have been following Bucky's tutorial on YouTube.

I tried to pass shake speed through a listener activity to main activity. but the code just won't work. it says "the application has unfortunately stopped"



listener code:
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;


/**
* Listener that detects shake gesture.
*/
public class AccReader implements SensorEventListener {

Activity foo;

SensorManager manager;
Sensor accelerometer;

private static final int MIN_FORCE = 10;


private static final int MIN_DIRECTION_CHANGE = 3;


private static final int MAX_PAUSE_BETHWEEN_DIRECTION_CHANGE = 200;


private static final int MAX_TOTAL_DURATION_OF_SHAKE = 400;


private long mFirstDirectionChangeTime = 0;


private long mLastDirectionChangeTime;

/** How many movements are considered so far. */
private int mDirectionChangeCount = 0;

/** The last x position. */
private float lastX = 0;

/** The last y position. */
private float lastY = 0;

/** The last z position. */
private float lastZ = 0;

/** OnShakeListener that is called when shake is detected. */
private OnShakeListener mShakeListener;

private float totalMovement;

public AccReader(Activity foo) {
this.foo = foo;
manager = (SensorManager) this.foo.getSystemService(Context.SENSOR_SERVICE);
accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
manager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
}


/**
* Interface for shake gesture.
*/
public interface OnShakeListener {

/**
* Called when shake gesture is detected.
*/
void onShake();
}


public void setOnShakeListener(OnShakeListener listener) {
mShakeListener = listener;
}

public float getTotalMovement(){

return this.totalMovement;
}

@Override
public void onSensorChanged(SensorEvent se) {
// get sensor data
float x = se.values[SensorManager.DATA_X];
float y = se.values[SensorManager.DATA_Y];
float z = se.values[SensorManager.DATA_Z];

// calculate movement
totalMovement = Math.abs(x + y + z - lastX - lastY - lastZ);

if (totalMovement > MIN_FORCE) {

// get time
long now = System.currentTimeMillis();

// store first movement time
if (mFirstDirectionChangeTime == 0) {
mFirstDirectionChangeTime = now;
mLastDirectionChangeTime = now;
}

// check if the last movement was not long ago
long lastChangeWasAgo = now - mLastDirectionChangeTime;
if (lastChangeWasAgo < MAX_PAUSE_BETHWEEN_DIRECTION_CHANGE) {

// store movement data
mLastDirectionChangeTime = now;
mDirectionChangeCount++;

// store last sensor data
lastX = x;
lastY = y;
lastZ = z;

// check how many movements are so far
if (mDirectionChangeCount >= MIN_DIRECTION_CHANGE) {

// check total duration
long totalDuration = now - mFirstDirectionChangeTime;
if (totalDuration < MAX_TOTAL_DURATION_OF_SHAKE) {
mShakeListener.onShake();
resetShakeParameters();
}
}

} else {
resetShakeParameters();
}
}
}

/**
* Resets the shake parameters to their default values.
*/
private void resetShakeParameters() {
mFirstDirectionChangeTime = 0;
mDirectionChangeCount = 0;
mLastDirectionChangeTime = 0;
lastX = 0;
lastY = 0;
lastZ = 0;
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}

}





main activity code:


import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;




public abstract class MainActivity extends AppCompatActivity implements SensorEventListener {

private SensorManager mSensorManager;
private AccReader mSensorListener;
private Sensor mAccelerometer;
AccReader acc;
private EditText output;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(new AccReader(this), mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
output = (EditText) findViewById(R.id.editText1);
acc = new AccReader(this);

mSensorListener.setOnShakeListener(new AccReader.OnShakeListener() {
@Override
public void onShake() {
refresh();
}

});

}

public void refresh(){
output.setText("X:"+acc.getTotalMovement());
}





@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(mSensorListener,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_UI);
}

@Override
protected void onPause() {
mSensorManager.unregisterListener(mSensorListener);
super.onPause();
}



}



Please look at the code and tell me where am I going wrong.


p.s. I'm COMPLETELY new to this. Do explain a bit. :)