我的代码中的最后两个方法在这行代码(2 client.get(WEATHER_URL, params, new JsonHttpResponseHandler(){
部分)之后给出了错误@Override
。它只是不理解方法或什么?
final String WEATHER_URL = "http://api./openweathermap.org/data/2.5/weather";
final String APP_ID = "e72ca729af228beabd5d20e3b7749713";
//setting variables
final int REQUEST_CODE =123;
long MIN_TIME = 5000;
float MIN_DISTANCE = 1000;
// Set Location-Provider:
String LOCATION_PROVIDER = LocationManager.GPS_PROVIDER;
LocationManager mLocationManager;
LocationListener mLocationListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weather_layout);
mButton_change = (ImageButton) findViewById(R.id.change_button);
mButton_change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, change_the_location.class);
startActivity(intent);
}
});
}
@Override
protected void onResume() {
super.onResume();
Log.d("asdasd", " asd");
getWeatherForCurrentLocation();
}
private void getWeatherForCurrentLocation() {
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
String longitude = String.valueOf(location.getLongitude());
String latitude = String.valueOf(location.getLatitude());
Log.d("Clima", "OnLocationcahnge() recieved");
RequestParams params = new RequestParams();
params.put("lat", latitude);
params.put("long", longitude);
params.put("appid", APP_ID);
letsDoSomeNetworking(params);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Clima", "OnProviderDisabled recieved");
}
};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_CODE);
return;
}
mLocationManager.requestLocationUpdates(LOCATION_PROVIDER, MIN_TIME, MIN_DISTANCE, mLocationListener);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == REQUEST_CODE){
if(grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED){
Log.d("Clima", "Requestpermissionresult() ");
getWeatherForCurrentLocation();
}else{
Log.d(" CLiama", "Permission denied!!!!!!!!!!!!!");
}
}
}
private void letsDoSomeNetworking(RequestParams params){
AsyncHttpClient client = new AsyncHttpClient();
client.get(WEATHER_URL, params, new JsonHttpResponseHandler(){
@Override
public void OnSuccess(int statusCode, Header[] headers, JSONObject response){
Log.d("Clima", "Here is JSONTEXT: " + response.toString());
}
@Override
public void OnFailure(int statusCode, Header[] headers, Throwable e, JSONObject response){
Log.e("Clima", "Fail to response" + e.toString());
Log.d("Clima", "Status Code " + statusCode);
Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT).show();
}
});
}
}
答案 0 :(得分:0)
检查您是否正在使用正确的课程:
spring.security.enabled=false
这应该是正确的覆盖:
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.json.JSONObject;
(似乎它只是“OnSuccess”和“OnFailure”中的首都“O”)