Hullu2000
Hullu2000

Reputation: 261

Problems with AIDE apps

I'm developing Android apps on my phone, on the app AIDE. Its a very useful tool. But when AIDE says there are no errors and I install my app and run it, I get a promt: "Unfortunately, (App name here) has stopped."

I don't know the reason, but it seams to happen, when the app uses the gyroscope or have a Display variable or something like that. Some times it just comes for no reason.

AIDE says that this code is fine but it does not work.

package com.test.gyro;

import android.app.*;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.*;
import android.widget.*;

public class MainActivity extends Activity implements SensorEventListener
{
    private SensorManager SM;
    private Sensor gyro;
    private TextView text;

    @Override
    public void onCreate(Bundle SIS)
    {
        super.onCreate(SIS);
        SM = (SensorManager) this.getSystemService(SENSOR_SERVICE);
        gyro = SM.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
        text.setText("null");
        setContentView(text);
    }

    public void onSensorChanged(SensorEvent e)
    {
        String m=e.values[0] + ", " + e.values[1] + ", " + e.values[2];
        text.setText(m);
        text.invalidate();
    }

    public void onAccuracyChanged(Sensor S, int a)
    {
    }
}

Upvotes: 1

Views: 2993

Answers (1)

Alexis C.
Alexis C.

Reputation: 93872

You didn't initialized your textView variable. So when you're doing text.setText("null"), it throws a NullPointerException and stop your app.

Initialize your textView and retry to launch it.

Upvotes: 4

Related Questions