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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:02:41+00:00 2026-05-18T11:02:41+00:00

The idea is when there is no internet connection available, show my custom dialog

  • 0

The idea is when there is no internet connection available, show my custom dialog to users which indicates there is no connection. Otherwise, when page is loading in WebView, show a ProgressDialog to show that page is loading and dismiss when loading is done. When there is an internet connection this code works, but if there is no, it crashes and I can’t find where the error is.

package com.tariknotebook;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class NoteBook extends Activity {
    /** Called when the activity is first created. */
    WebView web;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        web = (WebView) findViewById(R.id.browserMine);
        web.setWebViewClient(new HelloWebViewClient());
        web.getSettings().setJavaScriptEnabled(true);
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        web.loadUrl("http://m.seslisozluk.com");
    }

    ProgressDialog dialog;
    Dialog connDialog;

    @Override
    protected Dialog onCreateDialog(int id) {

        switch(id)
        {
        case 1:
            dialog = ProgressDialog.show(NoteBook.this, "Loading",
            "Loading.. Please wait.");

            break;
        case 2:
                connDialog = new Dialog(getApplicationContext());
                connDialog.setContentView(R.layout.connection);
                connDialog.setTitle("No Internet Connection");

                Button closeButton = (Button) findViewById(R.id.closeButton);
                closeButton.setOnClickListener(new closeButtonOnClickListener());
                connDialog.show();
            break;
        }


        return super.onCreateDialog(id);
    }

    private class closeButtonOnClickListener implements OnClickListener
    {
        public void onClick(View v) {
            connDialog.dismiss();
        };
    }

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
                ConnectivityManager conStatus = (ConnectivityManager) view.getContext().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
                if(conStatus.getActiveNetworkInfo().isConnected() && conStatus.getActiveNetworkInfo() != null)
                    showDialog(1);
                else
                    showDialog(2);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            dialog.dismiss();

        }

    }
}

And this is the error log as well :

error log

  • 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-18T11:02:41+00:00Added an answer on May 18, 2026 at 11:02 am

    When you post error messages, you should tell us which line of the source corresponds.

    By pasting your code into a text editor, I believe line 83 is:


    if(conStatus.getActiveNetworkInfo().isConnected() && conStatus.getActiveNetworkInfo() != null)

    This strongly suggests that conStatus is null and you are trying to call a method of non-existent object.

    You should check that it’s non-null first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app in which I'm trying to detect WHEN the Internet connection
I want set Listbox background to transparent but not working Is there any idea?
I want city name from IP address using Java is there any idea to
My idea is like if there is a exist file , add the filename
Is there a way with IntelliJ Idea, to create two kinds of artifacts -
Are there any cases when it's a good idea to throw errors that can
In datasets there was a method WriteXml or ReadXml Does anyone have any idea
I was wondering if there's anyone having an idea how to tackle with the
Is there a mechanism to dynamically load a GWT Module? The idea is to
There is almost identical question , but I have no idea what to do

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.