gpt4 book ai didi

java - 我正在开发一个简单的计步器应用程序,它有这些错误,代码如下

转载 作者:行者123 更新时间:2023-12-01 08:46:15 26 4
gpt4 key购买 nike

package com.example.ritwik.letswalk;

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.widget.Toast;

public class MainActivity extends AppCompatActivity implements SensorEventListener{


TextView tv_steps;

SensorManager sensorManager;
boolean running=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv_steps=(TextView) findViewById(r.id.tv_steps);
sensorManager=(SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume()
{
super.onResume();
running=true;
Sensor countSensor=sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if(countSensor==null){
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
}
else
Toast.makeText(this, "Sensor Not Found",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause()
{
super.onPause();
running=false;
}
@Override
protected void onSensorChangeed(SensorEvent event)
{
if(running)
{
tv_steps.setText(String.valueOf(event.values[0]));
}
}
}

代码有以下错误

Error:(21, 15) error: cannot find symbol class TextView Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details. Error:(12, 5) error: cannot find symbol class TextView Error:(43, 37) error: cannot find symbol class SensorEvent Error:(11, 8) error: MainActivity is not abstract and does not override abstract method onAccuracyChanged(Sensor,int) in SensorEventListener Error:(21, 39) error: package r does not exist Error:(42, 5) error: method does not override or implement a method from a supertype

最佳答案

SensorEventListener 有两个抽象方法:

1) onAccuracyChanged(传感器传感器, int 精度)2)onSensorChanged(SensorEvent事件)

您还需要重写 onAccuracyChanged 方法。

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

}

当传感器的精度发生变化时,会调用此方法。如果您不想在这里做任何事情,那么就不要在这里编写任何代码。但由于它是抽象的,因此您需要实现它。

希望有帮助。

关于java - 我正在开发一个简单的计步器应用程序,它有这些错误,代码如下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43027117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com