• Register
0 votes
284 views

Problem :

I am beginner in Android Studio and I have written code, but I keep facing below error if I try to run my code:
"Error: method does not override or implement a method from a supertype".

I have already spent over four hours on this error but I am unable to fix it.
Can somebody help me in fixing this issue?

8 4 2
2,300 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I can give you very simple generalized solution on your issue, I guess you must have used the @Override tag it will add the compile time check to make sure if your method is overriding the method from the super class.

And you must have written a method call for which there is no method present in any of the Android's Activity classes then you just cannot override it.

In that case you must remove the @Override tag from your code to make your code compile. however onCreate2() will never execute. Please note you cannot just write random methods into your class and then expect that they will be executed. They must be called from somewhere if a method is not getting called then it and will not be compiled with the wrong @Override tag.

I hope the solution will help you in resolving your error.

 
 
5 2 1
4,980 points
0 votes

Solution:

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.

Follow the below code:

client.get(QUERY_URL + urlString,
    new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(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());
        }

        @Override
        public void onFailure(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.

If it is not solved yet then try this below code

public class BatteryStatusPackage implements ReactPackage {

public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new BatteryStatusModule(reactContext));

    return modules;
}

public List<Class<? extends JavaScriptModule>> createJSModules() {
    return Collections.emptyList();
}

public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Collections.emptyList();
}
}

 

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 90 views
90 views
I want to know how to fix this. Could anyone here help me out?
asked Dec 16, 2020 TeamScript 13.5k points
3 votes
2 answers 1.2K views
1.2K views
Problem: I am assuming a bunch of helpful souls are roaming here, in Kodlogs. I am trying to figuring out the abstract method in Java and wrote a simple program on it. Unfortunately, my program throws back an error and says, AbstractClassExample.java:9: error: AbstractClassExample ... (String args[]) { new AbstractClassExample().display(); } } Do you have any idea or solution for me? Thanks, guys.
asked Mar 25, 2020 Gavin 15.3k points
0 votes
1 answer 117 views
117 views
Problem: I have recently started working on Android Project. I have managed to gain only basic knowledge related to Android Programming with the help of online tutorials. After trying to import my Eclipse project into the android Studio then I had ... (); public static SetContentView setContentView; public static Activity activity; public static Context context; public static boolean wait = true;
asked Jul 15, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 8 views
8 views
Problem : When upgraded to Xcode 6.3 Beta 3 and a lot of error(s) are appearing relating to the following: Initializer does not override a designated initializer from its superclass. Can someone please help fix this, I am new in IOS Swift .
asked Mar 20 Shovo210 13.2k points
0 votes
1 answer 10 views
10 views
Solve this problem.
asked Dec 18, 2020 TeamScript 13.5k points
0 votes
1 answer 19 views
19 views
I am new to this. I was doing that but I got into some problems.
asked Dec 3, 2020 TeamScript 13.5k points
0 votes
1 answer 726 views
726 views
Problem : I am trying to learn Java, I am very newbie however I wanted to know what I do to get the "run" it. I am facing below error: Static Error: This class does not have a static void main method accepting String[]. Below is my code: public class MyCaneirinho { public static void mycontar ... { System.out.println(j + x + y); } else { System.out.println(j + x + y + z); } } } } // MyCarneirinho
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 65 views
65 views
Problem the environment variable java_home does not point to a valid jvm installation
asked Feb 9 charles mathews 5.5k points
0 votes
1 answer 92 views
92 views
Problem : While executing Android code getting below error java.lang.illegalstateexception could not execute method of the activity
asked Oct 23, 2019 peterlaw 6.9k points