加速度計を使用するアプリを作成しようとしていますが、アプリを実行すると、残念ながらアプリが停止したと表示されます。他のコードがありましたが、コードを台無しにしていると思ったので削除しましたが、そうではありませんでした。
ここにコードがあります
`
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent one = new Intent(getApplicationContext(), act.class);
startActivity(one);
}
}
class act extends Activity implements SensorEventListener {
Intent one = getIntent();
private SensorManager sensorManager;
private Sensor accelerometer;
float x,y,z;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
protected void onResume() {
super.onResume();
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor accelerometer, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
}
}`
両方のクラスが同じファイルにあります
LogCat:
02-19 14:32:24.490: E/AndroidRuntime(7916): FATAL EXCEPTION: main
02-19 14:32:24.490: E/AndroidRuntime(7916): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a3/com.example.a3.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.a3/com.example.a3.act}; have you declared this activity in your AndroidManifest.xml?
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.os.Looper.loop(Looper.java:137)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-19 14:32:24.490: E/AndroidRuntime(7916): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 14:32:24.490: E/AndroidRuntime(7916): at java.lang.reflect.Method.invoke(Method.java:511)
02-19 14:32:24.490: E/AndroidRuntime(7916): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-19 14:32:24.490: E/AndroidRuntime(7916): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-19 14:32:24.490: E/AndroidRuntime(7916): at dalvik.system.NativeStart.main(Native Method)
02-19 14:32:24.490: E/AndroidRuntime(7916): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.a3/com.example.a3.act}; have you declared this activity in your AndroidManifest.xml?
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Activity.startActivityForResult(Activity.java:3370)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Activity.startActivityForResult(Activity.java:3331)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Activity.startActivity(Activity.java:3566)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Activity.startActivity(Activity.java:3534)
02-19 14:32:24.490: E/AndroidRuntime(7916): at com.example.a3.MainActivity.onCreate(MainActivity.java:32)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Activity.performCreate(Activity.java:5104)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-19 14:32:24.490: E/AndroidRuntime(7916): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-19 14:32:24.490: E/AndroidRuntime(7916): ... 11 more