Method Does Not Override Or Implement A Method From A Supertype - For Override
Solution 1:
The problem is what the error message is saying: "the method does not override or implement a method from a supertype". You annotated both methods with the Override annotation, however, no method with the same signature (i.e. the parameters) can be found in the supertype (JsonHttpResponseHandler).
If you take a look at the documentation of JsonHttpResponseHandler, you can see all the available onSuccess(...) and onFailure(...) methods.
Here is the working version of your code (note that changes in the method signatures):
client.get(QUERY_URL + urlString,
newJsonHttpResponseHandler() {
@OverridepublicvoidonSuccess(int statusCode, org.apache.http.Header[] headers, JSONObject jsonObject) {
// Display a "Toast" message// to announce your success
Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
// 8. For now, just log results
Log.d("omg android", jsonObject.toString());
}
@OverridepublicvoidonFailure(int statusCode, org.apache.http.Header[] headers, Throwable throwable, JSONObject error) {
// Display a "Toast" message// to announce the failure
Toast.makeText(getApplicationContext(), "Error: " + statusCode + " " + throwable.getMessage(), Toast.LENGTH_LONG).show();
// Log error message// to help solve any problems
Log.e("omg android", statusCode + " " + throwable.getMessage());
}
});
Note that starting from Android 6.0 (API level 23) the Apache library (org.apache.http.*) is not available anymore. If you want to continue using that, see Behavior Changes for more information.
Some personal opinion: I wouldn't recommend using the Asynchronous HTTP Library as it's built on top of the obsolete (and from API level 23, removed) Apache HttpClient, which has poor performance compared to HttpURLConnection. Quote from the Android developers about HttpURLConnection:
This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.
Solution 2:
Easy solution to fixed above issue
Wrong code:
publicclassBatteryStatusPackageimplementsReactPackage {
@OverridepublicList<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = newArrayList<>();
modules.add(newBatteryStatusModule(reactContext));
return modules;
}
@OverridepublicList<Class<? extendsJavaScriptModule>> createJSModules() {
returnCollections.emptyList();
}
@OverridepublicList<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
returnCollections.emptyList();
}
}
Answer :
Here i just removed @override
publicclassBatteryStatusPackageimplementsReactPackage {
publicList<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = newArrayList<>();
modules.add(newBatteryStatusModule(reactContext));
return modules;
}
publicList<Class<? extendsJavaScriptModule>> createJSModules() {
returnCollections.emptyList();
}
publicList<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
returnCollections.emptyList();
}
}
Solution 3:
I am not sure which version of loopj library you are using, but from this Javadoc link, your onSuccess and onFailure method signatures are both different.
They have to be,
@Override
public void onSuccess(int statusCode,
org.apache.http.Header[] headers,
org.json.JSONObject response) {}
@Override
public void onFailure(int statusCode,
org.apache.http.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONObject errorResponse) {}
Note the headers parameter you have missed.
Solution 4:
The tutorial you're following uses version 1.4.4 of the Asynchronous Http Client library. You're probably using another version.
Either specify this version on your Gradle configuration:
dependencies {
...
compile'com.loopj.android:android-async-http:1.4.4'
...
}
Or change your definition to reflect the method signatures of the version you're using, for example for 1.4.8 (latest):
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// ...
}
@Override
public void onFailure(int statusCode,
org.apache.http.Header[] headers,
java.lang.Throwable throwable,
org.json.JSONObject errorResponse) {
// ...
}
Post a Comment for "Method Does Not Override Or Implement A Method From A Supertype - For Override"