Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我有这个无默认构造函数错误?意图服务错误_Java_Android - Fatal编程技术网

Java 为什么我有这个无默认构造函数错误?意图服务错误

Java 为什么我有这个无默认构造函数错误?意图服务错误,java,android,Java,Android,我正试图通过一个应用程序获取一个位置的坐标,但是在清单文件中,GPSTracker的下划线为红色,表示没有默认构造函数,我想知道是什么问题,谢谢。下面是跟踪器文件代码 public class GPSTracker extends Service implements LocationListener { private final Context mContext; boolean isGPSEnabled = false; // flag for GPS status boolean is

我正试图通过一个应用程序获取一个位置的坐标,但是在清单文件中,GPSTracker的下划线为红色,表示没有默认构造函数,我想知道是什么问题,谢谢。下面是跟踪器文件代码

public class GPSTracker extends Service implements LocationListener {

private final Context mContext;
boolean isGPSEnabled = false; // flag for GPS status
boolean isNetworkEnabled = false; // flag for network status
boolean canGetLocation = false; // flag for GPS status


Location location; // location
double latitude; // latitude
double longitude; // longitude

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters

private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;

protected LocationManager locationManager;



public GPSTracker(Context context) {
    this.mContext = context;
    getLocation();

}


public Location getLocation() {
    try {
        locationManager = 
(LocationManager)mContext.getSystemService(LOCATION_SERVICE);

        isGPSEnabled = 
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        // getting network status
        isNetworkEnabled = 
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {

        } else {
            this.canGetLocation = true;
            if (isNetworkEnabled) {
                if (ActivityCompat.checkSelfPermission(mContext, 
 Manifest.permission.ACCESS_FINE_LOCATION) != 
 PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_COARSE_LOCATION) !=
                        PackageManager.PERMISSION_GRANTED) {

您需要向GPSTracker添加默认构造函数

public GPSTracker() {
   //implement
}

服务继承上下文。您不需要向构造函数添加其他上下文,但需要编写:

locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);

这个问题与C++相关?我没有看到C++代码,也没有提到JNI。问题是缺少一个没有参数的构造函数:<代码>公共gpStReCar(){{} /Cord> >,在<代码>服务< /代码>中,您不应该有明确定义的构造函数。删除您拥有的一个-
public-GPSTracker(Context-Context){…}
。OP的目的是了解尽管定义了一个构造函数,但为什么会引发异常。i、 e.为什么要授权?为什么在没有定义其他构造函数的情况下不强制执行它?我相信OP期待这些问题的答案EA,但我试过了,不起作用,相反,mcontext变量的另一个错误可能没有初始化。请发布您的mainfest