hosheazhang
hosheazhang
采纳率100%
2019-03-06 19:39

AndroidStudio 实例化了但是报unknown class错误

package com.example.a54297.myapplication;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    TextView tvSensors = (TextView) findViewById(R.id.tv_sensors);
    //获取传感器SensorManager对象
    SensorManager mSensorManager;
    List<Sensor> sensorList;

    mSensorManager = (SensorManager)getsystemService(Context.SENSOR_SERVICE);

    sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
    List<String> sensorNameList = new ArrayList<String>();

}

我已经声明了mSensorManager和sensorList,但是在倒数第八行以及倒数第五行程序中报unknow class错误

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • oSanYeCao1234567 RoidCoder 2年前

    你没有导入包吧
    import android.hardware.SensorManager;
    import android.hardware.Sensor;

    点赞 评论 复制链接分享

相关推荐