0

I am dealing with that problem:

Fatal Exception: java.lang.NoSuchMethodError
No virtual method getActiveNetwork()Landroid/net/Network; in class Landroid/net/ConnectivityManager; or its super classes (declaration of 'android.net.ConnectivityManager' appears in /system/framework/framework.jar:classes2.dex)

There is my code:

 public boolean isNetworkAvailable() {

        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        if (connectivityManager != null) {


            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
                NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
                if (capabilities != null) {
                    if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {

                        return true;
                    } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {

                        return true;
                    } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {

                        return true;
                    }
                }
            }
        }

    return false;}

there is the stacktrace:

Fatal Exception: java.lang.NoSuchMethodError: No virtual method getActiveNetwork()Landroid/net/Network; in class Landroid/net/ConnectivityManager; or its super classes (declaration of 'android.net.ConnectivityManager' appears in /system/framework/framework.jar:classes2.dex)
   at com.olgazelenko.esofer.MainMenu.isNetworkAvailable(MainMenu.java:307)
   at com.olgazelenko.esofer.MainMenu.onCreate(MainMenu.java:75)
   at android.app.Activity.performCreate(Activity.java:6178)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
   at android.app.ActivityThread.access$900(ActivityThread.java:177)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5910)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

does someone know how that can be fixed?

6
  • Please add the complete stack trace. Commented Oct 1, 2020 at 9:39
  • check it out: justpaste.it/5q7ja Commented Oct 1, 2020 at 9:44
  • 2
    Please include it in your question and not on any website. Commented Oct 1, 2020 at 9:48
  • Also this is not the complete stack trace. Commented Oct 1, 2020 at 9:48
  • ok check it out now Commented Oct 1, 2020 at 9:50

1 Answer 1

2

This Error occurs often when you have compiled with one version of your dependency but are running the code with a different version.

Here, it looks that com.olgazelenko.esofer.MainMenu.isNetworkAvailable(MainMenu.java:307) calls a method from android which is not found during your execution.

This method, getActiveNetwork, seemed to be added in Android SDK API Level 23. You maybe try to use it in a older version. see https://developer.android.com/reference/android/net/ConnectivityManager#getActiveNetwork(). Try to upgrade your minSdkVersion : https://developer.android.com/guide/topics/manifest/uses-sdk-element

Sign up to request clarification or add additional context in comments.

3 Comments

so basically i have to upgrade my minSkVersion to 23? i am on 22 right now.
ok got it.. i hope it is gonna work after i'm doing an update on my published app... thanks mate, answer accepted!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.