构造函数GPS(MainActivity)未定义

时间:2014-02-22 15:02:13

标签: java android class interface

在构建一个处理LocationManager接口(GPS)的类后,我收到此错误The constructor GPS(MainActivity) is undefined

......我完全是空白,我不知道该说些什么。我对java,class和interface没有太多经验。

代码张贴在下面。

MainActivity.java

package com.bz.example;

import android.app.Activity;
import android.os.Bundle;

import com.bz.example.libs.GPS;
import com.bz.example.libs.GPSpos;

public class MainActivity extends Activity implements GPSpos {

    private GPS gps;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        gps = new GPS(MainActivity.this);
    }

    public void locationChanged(double longitude, double latitude) {
    }

    @Override
    public void displayGPSSettingsDialog() {
    }
}

GPSpos.java

package com.bz.example.libs;

public interface GPSpos {
    public void locationChanged(double longitude, double latitude);
    public void displayGPSSettingsDialog();
}

GPS.java

package com.bz.example.libs;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GPS {

    private GPSpos main;

    // Helper for GPS-Position
    private LocationListener locationListener;
    private LocationManager locationManager;

    private boolean isRunning;

    public void GPS(GPSpos main)
    {
        this.main = main;

        locationManager = (LocationManager) ((Activity) this.main).getSystemService(Context.LOCATION_SERVICE);
        locationListener = new locationListener();
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, locationListener);
    }

   public void stopGPS() {
        if(isRunning) {
            locationManager.removeUpdates(locationListener);
            this.isRunning = false;
        }
    }

    public void resumeGPS() {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, locationListener);
        this.isRunning = true;
    }

    public boolean isRunning() {
        return this.isRunning;
    }

    public class locationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location loc) {
            GPS.this.main.locationChanged(loc.getLongitude(), loc.getLatitude());
        }

        @Override
        public void onProviderDisabled(String provider) {
            GPS.this.main.displayGPSSettingsDialog();
        }

        @Override
        public void onProviderEnabled(String provider) {}

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {}

    }
}

1 个答案:

答案 0 :(得分:2)

删除void

 public void GPS(GPSpos main)
        ^^^^ - constructors in java dont have return type