Android - RuntimeException, where goes wrong?
<p>In this app, I have 3 buttons and 1 textView.
In the current stage, I leave basically a lot of things blank.
e.g. I have not implemented the button functions yet.</p>

<p>But now there is a runtime error inside.
Even the elements cannot be displayed out.</p>

<p>could you please help?</p>

<pre><code>import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements SensorEventListener {

    Button startButton;
    Button pauseButton;
    Button resetButton;
    TextView textView = (TextView) findViewById(R.id.textView1);

    private SensorManager sensorManager;
    private long lastUpdate;

    private boolean isCalibrated = false;
    private int referrenceAxis;
    private int stepCounts = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // start button
        startButton = (Button) findViewById(R.id.button1);
        startButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        // pause button
        pauseButton = (Button) findViewById(R.id.button2);
        pauseButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        // reset button
        resetButton = (Button) findViewById(R.id.button3);
        resetButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        init();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void init() {
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        lastUpdate = System.currentTimeMillis();
    }

    public void onSensorChanged(SensorEvent event) {

        if (event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
            long actualTime = System.currentTimeMillis();

            if (isCalibrated &amp;&amp; (actualTime - lastUpdate &gt; 500)) {
                if (event.values[referrenceAxis] &gt; 1) {
                    stepCounts++;
                }
            }

        }

        if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
            if (!isCalibrated) {

                if ((event.values[0] &gt;= event.values[1])&amp;&amp;(event.values[0] &gt;= event.values[2]))
                    referrenceAxis = 0;
                if ((event.values[1] &gt;= event.values[0])&amp;&amp;(event.values[1] &gt;= event.values[2]))
                    referrenceAxis = 1;
                if ((event.values[2] &gt;= event.values[0])&amp;&amp;(event.values[2] &gt;= event.values[1]))
                    referrenceAxis = 2;

                isCalibrated = true;
            }
        }
    }

    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }

    protected void onResume() {
        super.onResume();
        // register this class as a listener for the sensors
        sensorManager
                .registerListener(this, sensorManager
                        .getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                        SensorManager.SENSOR_DELAY_NORMAL);
        sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    protected void onPause() {
        // unregister listener
        super.onPause();
        sensorManager.unregisterListener(this);
    }

}
</code></pre>
