Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:13:44+00:00 2026-06-11T21:13:44+00:00

I know this topic has already been asked here, but I don’t understand why

  • 0

I know this topic has already been asked here, but I don’t understand why my code is not working as expectd. I need to check data connectivity at launch of my app, but it crashes on some tablets (as Nexus 7), but not on all.

My code :

public static boolean getNetworkState(Context pContext)
{
    ConnectivityManager connect =  (ConnectivityManager)pContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    if(connect != null)
    {
        if (connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting())
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    else
        return false;
}

public static boolean getWifiState(Context context)
{
    ConnectivityManager connect =  (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if ( connect.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting())
    {
        return true;
    }
    else 
    {
        return false;
    }
}

Connectivity check :

if(Commons.getNetworkState(this) || Commons.getWifiState(this))
        {
            loadData();
        }
        else
        {
            Commons.getConnectivityErrorMessage(this);
        }

Normally, if network connectivity is not supported on tablet, the “connectivity” object in “getNetworkState” should be null but it seems it’s not the case because it crashed on line

 if (connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting())

What’s wrong here?
Permissions are already written

EDIT : Unfortunately, I don’t have a tablet to test the problem. I just have user report on developer console. The following report has been reported by an user with a Nexus 7 :

java.lang.RuntimeException: Unable to resume activity {com.meteociel.fr/com.meteociel.fr.activities.MeteocielActivity}: java.lang.RuntimeException: Unable to resume activity {com.meteociel.fr/com.meteociel.fr.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to resume activity {com.meteociel.fr/com.meteociel.fr.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:178)
at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:523)
at android.app.ActivityGroup.onResume(ActivityGroup.java:61)
at com.meteociel.fr.activities.MeteocielActivity.onResume(MeteocielActivity.java:69)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
at android.app.Activity.performResume(Activity.java:5082)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
... 12 more
Caused by: java.lang.NullPointerException
at com.meteociel.fr.classes.Commons.getNetworkState(Commons.java:36)
at com.meteociel.fr.activities.HomeActivity.onResume(HomeActivity.java:98)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
at android.app.Activity.performResume(Activity.java:5082)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
... 19 more

EDIT 2 : all the permissions which I use :

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:13:45+00:00Added an answer on June 11, 2026 at 9:13 pm

    This code works now :

    public static boolean getNetworkState(Context pContext)
        {
            ConnectivityManager connect = null;
            connect =  (ConnectivityManager)pContext.getSystemService(pContext.CONNECTIVITY_SERVICE);
    
            if(connect != null)
            {
                NetworkInfo result = connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                if (result != null && result.isConnectedOrConnecting())
                {
                    return true;
                }
                else 
                {
                    return false;
                }
            }
            else
                return false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this topic has been already beaten enough, but I still don't
I know this topic has been discussed, but not by me yet. As I
i know this topic has been discussed here before but i still can't get
I know this topic has been discussed but I think it has some differences.
I know this topic has been covered ad nauseam here, and other places on
I know this topic has been discussed to death, but there is one thing
I know this topic has been beaten to death a little on SO, but
Ok so I know this topic has many questions, but I still haven't been
I know this has been a hot topic over the time... but I can't
I know this topic has been discussed a lot , but I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.