2017-06-29 24 views
1

我正在尝试编写一个Android应用程序以进行投放。很大一部分是找到移动设备的当前位置。Android应用程序 - 位置服务的@Override方法中的错误

我遵循的所有教程都给出了我无法弄清楚或理解的相同错误,我是Android开发新手。

我收到的错误是“错误:(76,5)错误:方法没有覆盖或实现超类型的方法”。

我的代码:

public class LoginActivity extends AppCompatActivity { 
protected LocationManager locationManager; 
protected LocationListener locationListener; 
protected Context context; 
String tempLocation; 
String lat; 
String provider; 
protected String latitude,longitude; 
protected boolean gps_enabled,network_enabled; 

public static String pName; 
public static String pID; 

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


    //Get Input 
    etUsername = (EditText) findViewById(R.id.txtLoginUserName); 
    etPassword = (EditText) findViewById(R.id.txtLoginPassword); 




    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) this); 

} 
@Override 
public void onLocationChanged(Location location) { 
    tempLocation = "Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude(); 
    TextView lg = (TextView) findViewById(R.id.txtLoginUserName); 
    lg.setText(tempLocation); 
} 

@Override 
public void onProviderDisabled(String provider) { 
    Log.d("Latitude","disable"); 
} 

@Override 
public void onProviderEnabled(String provider) { 
    Log.d("Latitude","enable"); 
} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    Log.d("Latitude","status"); 
} 

和我的结果日志:

Error:(76, 5) error: method does not override or implement a method from a supertype 
Error:(83, 5) error: method does not override or implement a method from a supertype 
Error:(88, 5) error: method does not override or implement a method from a supertype 
Error:(93, 5) error: method does not override or implement a method from a supertype 
:app:compileDebugJavaWithJavac FAILED 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 
Information:BUILD FAILED 
Information:Total time: 1.661 secs 
Information:5 errors 
Information:0 warnings 
Information:See complete output in console 

我用这tutorial

任何帮助或建议,将不胜感激,因为我试图使用许多不同的答案,但目前为止没有真正的帮助。

+0

显示您的类声明。 – shmosel

+0

你班上的班级是什么? –

+0

添加了行公共类LoginActivity延伸AppCompatActivity,希望你的意思是@shmosel – GoodDisplayName

回答

1

你缺少你的类中的下列implements LocationListener ...

使用这样的

class LocationActivity extends AppCompatActivity implements LocationListener{ 

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Override 
public void onLocationChanged(Location location) { 

} 

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

} 

@Override 
public void onProviderEnabled(String provider) { 

} 

@Override 
public void onProviderDisabled(String provider) { 

} 


} 

,然后你就可以实现你想....希望它是什么帮你

+0

非常感谢,即刻工作。只是最后一个问题,我在我的AndroidManifest.xml下有,但收到了导致:java.lang.SecurityException:“gps”位置提供程序需要ACCESS_FINE_LOCATION权限。错误。任何想法为什么? – GoodDisplayName

+0

高兴地帮助您...还使用以下权限'<使用权限android:name =“android.permission.ACCESS_COARSE_LOCATION”/> '并检查您是否不允许权限...通过转到设置>应用程序>你的应用程序>从你的Android设备或模拟器的权限.. –

相关问题