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 7517035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:19:08+00:00 2026-05-30T01:19:08+00:00

In my application I’m querying a database via the use of a PHP script.

  • 0

In my application I’m querying a database via the use of a PHP script. Currently, it gets the information as soon as the app comes up on the screen. However, if you don’t have an internet connection it returns a NullPointerException because it’s not getting any data. I’ve since updated my code with a ConnectivityManager and NetworkInfo that displays a toast if the user is not connected to either their network or to a WiFi. The problem is it’s skipping this and just executing the rest of the code like normal.

public class Shc_BalloonSat_Activity extends Activity
{
int historyCountFromUser;
httpAPI api;
mapAPI map;
DecimalFormat df = new DecimalFormat("##.#####");
DecimalFormat decimalf = new DecimalFormat("##.######");
SharedPreferences pref;
Editor prefEditor;
String lastpacketsPHP;

// User to determine how many packet the user would like to see.
int userDefinedCount = 5;

/*
 *  Called when the activity is first created. 
*/

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String returned = "";
    lastpacketsPHP = "";
    pref = getSharedPreferences("shared_prefs", 0);
    prefEditor = pref.edit();
    prefEditor.putString(lastpacketsPHP, "/* PHP file url goes here */");
    prefEditor.commit();       

    if(!isNetworkConnected(this))
    {
        Toast.makeText(this, "Please connect to the internet to access the full functionality of this app.", Toast.LENGTH_LONG).show();
    }

    else
    {
         api = new httpAPI(this);
         map = new mapAPI(this);

        try
        {
            returned = api.getData();
        }

        catch (Exception e)
        {
            e.printStackTrace();
        }

        TextView infoTV = (TextView)this.findViewById(R.id.info);
        infoTV.setText(returned);
        assignInfoToInfoTextView();
        assignInfoToHistoryTextView();
    }

}

public boolean isNetworkConnected(Context context)
{
    ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectionManager.getActiveNetworkInfo() != null && connectionManager.getActiveNetworkInfo().isAvailable() && connectionManager.getActiveNetworkInfo().isConnected())
    {
        return true;
    }

    else 
    {
        return false;
    }
}

Any ideas what I’m doing wrong?

Update (LogCat error message):

02-19 13:55:19.450: E/log_tag(443): Error in HTTP connection: java.net.UnknownHostException: Host is unresolved: space.uah.edu:80
02-19 13:55:19.450: E/log_tag(443): Error converting result:     java.lang.NullPointerException
02-19 13:55:19.450: E/log_tag(443): Error in HTTP connection: java.net.UnknownHostException: Host is unresolved: space.uah.edu:80
02-19 13:55:19.450: E/log_tag(443): Error converting result: java.lang.NullPointerException
02-19 13:55:19.450: E/AndroidRuntime(443): Uncaught handler: thread main exiting due to uncaught exception
02-19 13:55:19.473: E/AndroidRuntime(443): java.lang.RuntimeException: Unable to start activity    ComponentInfo{shc_BalloonSat.namespace/shc_BalloonSat.namespace.Shc_BalloonSat_Activity}: java.lang.NullPointerException: println needs a message
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.os.Looper.loop(Looper.java:123)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread.main(ActivityThread.java:4363)
02-19 13:55:19.473: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
02-19 13:55:19.473: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:521)
02-19 13:55:19.473: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-19 13:55:19.473: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-19 13:55:19.473: E/AndroidRuntime(443):  at dalvik.system.NativeStart.main(Native Method)
02-19 13:55:19.473: E/AndroidRuntime(443): Caused by: java.lang.NullPointerException: println needs a message
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.util.Log.println(Native Method)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.util.Log.e(Log.java:208)
02-19 13:55:19.473: E/AndroidRuntime(443):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.assignInfoToInfoTextView(Shc_BalloonSat_Activity.java:173)
02-19 13:55:19.473: E/AndroidRuntime(443):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.onCreate(Shc_BalloonSat_Activity.java:75)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-19 13:55:19.473: E/AndroidRuntime(443):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
02-19 13:55 :19.473: E/AndroidRuntime(443):     ... 11 more
  • 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-05-30T01:19:11+00:00Added an answer on May 30, 2026 at 1:19 am

    Assuming your connection check logic working fine, make it as, if/else. If not connected show toast, else continue with logic.

         if(!isNetworkConnected(this))         {     
                Toast.makeText(this, "Please connect to the internet to access the full functionality of this app.", Toast.LENGTH_LONG).show();      
           }
    else
        {          
        TextView infoTV = (TextView)this.findViewById(R.id.info);     
        infoTV.setText(returned);      
        assignInfoToInfoTextView();     
        assignInfoToHistoryTextView(); 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application Specific Information: com.my-app failed to launch in time Elapsed total CPU time (seconds):
Application 1 - Opens a SqlConnection and a SqlTransaction against a SQLServer 2005 database
Application stores configuration data in custom section of configuration file. This information is used
Application I am developing does some kind of server-side authorization. Communication is done via
Application Specific Information: com.oneorangetree.iphoneexample failed to launch in time elapsed total CPU time (seconds):
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
my application use 10 threads that to read a lot of html file.similar the
Application uses Entity Framework 4.1 with database first approach. I have in database a
Application shows information about planets, their moons, and etc. It shows a list of
Application is to display device distance to GPS coordinate on screen of mobile device

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.