2017-11-19 22 views
0

コードの最後の2つのメソッドでこのコード行(@Override部分)の後にエラーclient.get(WEATHER_URL, params, new JsonHttpResponseHandler(){が返されました。方法や何かを理解していないだけですか?あなたは右のクラスをimprotingているメソッドがメソッドをオーバーライドしたり実装したりしない

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

チェック:

import com.loopj.android.http.AsyncHttpClient; 
import com.loopj.android.http.JsonHttpResponseHandler; 
import org.json.JSONObject; 

これは正しいオーバーライドする必要があります:

client.get("......", new JsonHttpResponseHandler() { 
    @Override 
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) 
    { 
     super.onSuccess(statusCode, headers, response); 

    } 

    @Override 
    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 
     super.onFailure(statusCode, headers, throwable, errorResponse); 
    } 
}); 

は(「それだけキャピタルのようだO "OnSuccess"と "OnFailure")

関連する問題