public class MainActivity extends Activity{ 
TextView datumText;
GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Gestures
    datumText = (TextView) findViewById(R.id.datumText);
    datumText.setText("ma");
    gestureDetector = new GestureDetector(this, new GestureListener());
    datumText.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            return true;
        }
    });
}
}
class GestureListener implements GestureDetector.OnGestureListener{
MainActivity mainActivity = new MainActivity();
public GestureListener(){
}
@Override
public boolean onDown(MotionEvent e) {
    return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
    return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    mainActivity.datumText.setText("di");
    return true;
}
}
I want to change the text on
TextView datumText;
whenever I do the onFling motion on the TextView on-screen. But I am getting a NullPointerException and I think it is because I am trying to call the setText() method on a null object.
Thanks in advance!
EDIT: Forgot to mention I use a MainActivity class and a second class. EDIT2: I know what the NullPointerException is caused by but I don't know how to solve it.
 
     
    