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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:40:02+00:00 2026-06-11T16:40:02+00:00

I’m trying to do network validation before my apps start. I just add the

  • 0

I’m trying to do network validation before my apps start. I just add the AlertDialog in if else condition where if no network it will prompt a dialog box and upon user clicks on OK button it will redirect to main menu. I dont know where i do wrong. Please help. Thanks

protected void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SharedPreferences myPrefs = this.getSharedPreferences("myPrefs",
                MODE_WORLD_READABLE);
        String username = myPrefs.getString("MEM1", "");
        if (username.equalsIgnoreCase("") || username.length() == 0) {
            toast("Please register to scan product. Only registered user able to scan the product");
            startActivity(new Intent(ProductPreview.this, MainMenu.class)); 
            finish();
        }
    ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    boolean connected = networkInfo != null && networkInfo.isAvailable()
            && networkInfo.isConnected();

    if (connected) {
        try {
            mAdapter = NfcAdapter.getDefaultAdapter(this);
            mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(
                    this, getClass())
                    .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
            // Setup an intent filter for all MIME based dispatches
            IntentFilter ndef = new IntentFilter(
                    NfcAdapter.ACTION_TECH_DISCOVERED);
            try {
                ndef.addDataType("*/*");
            } catch (MalformedMimeTypeException e) {
                throw new RuntimeException("fail", e);
            }
            mFilters = new IntentFilter[] { ndef, };
            // Setup a tech list for all NfcF tags
            mTechLists = new String[][] { new String[] { MifareClassic.class
                    .getName() } };

            Intent intent = getIntent();
            resolveIntent(intent);
        } catch (Exception ex) {
            ex.toString();
        }                
    } 
    else {          
         AlertDialog.Builder dialog = new AlertDialog.Builder(this);
         dialog.setTitle("Attention");
          dialog.setMessage("No Internet Connection. Please enable the wifi."
          ); dialog.setPositiveButton("OK", new
          DialogInterface.OnClickListener() { public void
          onClick(DialogInterface dialog, int whichButton) {
          startActivity(new Intent(ProductPreview.this, MainMenu.class)); 
          finish();
              }
          });
          dialog.show();            
    }
}

LogCat

09-21 19:19:05.825: E/AndroidRuntime(8413): FATAL EXCEPTION: main
09-21 19:19:05.825: E/AndroidRuntime(8413): java.lang.RuntimeException: Unable to resume activity {com.smartag.mdec.dev/com.smartag.mdec.dev.ProductPreview}: java.lang.NullPointerException
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.os.Looper.loop(Looper.java:137)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at java.lang.reflect.Method.invoke(Method.java:511)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at dalvik.system.NativeStart.main(Native Method)
09-21 19:19:05.825: E/AndroidRuntime(8413): Caused by: java.lang.NullPointerException
09-21 19:19:05.825: E/AndroidRuntime(8413):     at com.smartag.mdec.dev.ProductPreview.onResume(ProductPreview.java:176)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.Activity.performResume(Activity.java:5082)
09-21 19:19:05.825: E/AndroidRuntime(8413):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
09-21 19:19:05.825: E/AndroidRuntime(8413):     ... 12 more

OnResume

@Override
public void onResume() {
    super.onResume();
    //ValidateLogin();
    mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters,
            mTechLists);

}
  • 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-11T16:40:03+00:00Added an answer on June 11, 2026 at 4:40 pm

    //if you don’t have any method to do in onResume() just delete it or comment it.

    or just block the line ProductPreview.java:176 in your onresume method which is getting null over there.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.