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

  • Home
  • SEARCH
  • 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 9221139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:30:44+00:00 2026-06-18T03:30:44+00:00

I was wondering if I could get a second (or many for that matter)

  • 0

I was wondering if I could get a second (or many for that matter) set of eyes to help me with this. I cannot for the life of me figure what is causing this. Basically, this is just a wireless activity that allows you to change the wifi state. However, my code is kicking out a nullPointerException at the call of getWiFi();. Its also pointing to line 123 but I see nothing wrong. Can anyone see why this would crash? My permissions in the manifest are correct to my knowledge. Here is the code from the java file. Line 89 is where getWifi(); is called. Any help would be greatly appreciated.

Code for WirelessManager.java

import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
        import android.view.View.OnClickListener;
        import android.net.wifi.WifiInfo;
        import android.net.wifi.WifiManager;
        import android.widget.TextView;
        import android.widget.ImageView;
        import android.widget.Button;

        public class WirelessManager extends Activity {
    //index values to access the elements in the TextView array.
    private final int SSTRENGTH = 0;
    private final int WIFISTATE = 1;
    private final int IPADD     = 2;
    private final int MACADD    = 3;
    private final int SSID      = 4;
    private final int LINKSPD   = 5;    

    private TextView[] data_labels;
    private TextView name_label;
    private TextView enable_label;
    private Button state_button;
    private Button back_button;
    private WifiManager wifi;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info_layout);

        wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
        TextView[] titles = new TextView[6];
        data_labels = new TextView[6];

        int[] left_views = {R.id.first_title, R.id.second_title, R.id.third_title,
                       R.id.fourth_title, R.id.fifth_title};

        /*R.layout.info_layout is the same layout used for directory info.
         *Re-using the layout for this activity, so id tag names may not make sense,
         *but are in the correct order.
         */
        int[] right_views = {R.id.dirs_label, R.id.files_label, R.id.time_stamp,
                             R.id.total_size, R.id.free_space};
        String[] labels = {"Signal strength", "WIFI State", "ip address",
                          "mac address", "SSID", "link speed"};

        for (int i = 0; i < 5; i++) {
            titles[i] = (TextView)findViewById(left_views[i]);
            titles[i].setText(labels[i]);

            data_labels[i] = (TextView)findViewById(right_views[i]);
            data_labels[i].setText("N/A");
        }

        name_label = (TextView)findViewById(R.id.name_label);
        enable_label = (TextView)findViewById(R.id.path_label);
        state_button = (Button)findViewById(R.id.back_button);
        back_button = (Button)findViewById(R.id.zip_button);
        back_button.setText(" Back ");

        state_button.setOnClickListener(new ButtonHandler());
        back_button.setOnClickListener(new ButtonHandler());

        ImageView icon = (ImageView)findViewById(R.id.info_icon);
        icon.setImageResource(R.drawable.wireless);

        get_wifi();
    }

    private void get_wifi() {
        WifiInfo info = wifi.getConnectionInfo();
        int state = wifi.getWifiState();
        int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
        boolean enabled = wifi.isWifiEnabled();

        name_label.setText(info.getSSID());
        enable_label.setText(enabled ?"Your wifi is enabled" :"Your wifi is not enabled");
        state_button.setText(enabled ?"Disable wifi" : "Enable wifi");

        switch(state) {
            case WifiManager.WIFI_STATE_ENABLED:
                data_labels[WIFISTATE].setText(" Enabled");
                break;
            case WifiManager.WIFI_STATE_DISABLED:
                data_labels[WIFISTATE].setText(" Disabled");
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                data_labels[WIFISTATE].setText(" Being Disabled");
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                data_labels[WIFISTATE].setText(" Being Enabled");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                data_labels[WIFISTATE].setText(" Unknown");
                break;
        }
        if(enabled) {
            data_labels[IPADD].setText(FileManager.integerToIPAddress(info.getIpAddress()));
            data_labels[MACADD].setText(info.getMacAddress());
            data_labels[SSID].setText(info.getSSID());
            data_labels[LINKSPD].setText(info.getLinkSpeed() + " Mbps");
            data_labels[SSTRENGTH].setText("strength " + strength);
        }else {
            data_labels[IPADD].setText("N/A");
            data_labels[MACADD].setText(info.getMacAddress());
            data_labels[SSID].setText("N/A");
            data_labels[LINKSPD].setText("N/A");
            data_labels[SSTRENGTH].setText("N/A");
        }
    }

    private class ButtonHandler implements OnClickListener {

        public void onClick(View v) {

            if(v.getId() == R.id.back_button) {
                if(wifi.isWifiEnabled()){
                    wifi.setWifiEnabled(false);
                    state_button.setText("Enable wifi");
                }else {
                    wifi.setWifiEnabled(true);
                    state_button.setText("Disable wifi");
                    get_wifi();
                }   
            }else if(v.getId() == R.id.zip_button)
                finish();
        }
    }

}


Code for AndroidManifest.xml


        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="coxxxxxxxxxx"
      android:versionCode="100"
      android:versionName="1.0.0"
      android:installLocation="auto">
    <application android:icon="@drawable/icon" android:label="@string/app_name" >



        <activity android:name=".Settings" android:label="@string/app_name" />

        <activity android:name=".ProcessManager" android:label="@string/manager_act" />
        <activity android:name=".WirelessManager" android:label="Wireless Information" />
        <activity android:name=".ApplicationBackup" android:label="Installed Applications" />



                <activity android:name=".Main"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <data android:mimeType="*/*" />
                <category android:name="android.intent.category.OPENABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </activity>

        <activity android:name=".AudioPlayblack"
                  android:label="@string/media_dialog"
                  android:theme="@android:style/Theme.Dialog" />

        <activity android:name=".DirectoryInfo" android:enabled="true"
                  android:label="@string/dir_info">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <data android:mimeType="application/manager" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name=".HelpManager"
                  android:label="XXXXXXXXX"
                  android:theme="@android:style/Theme.Dialog" />


 </application>
            <supports-screens android:smallScreens="true"
                      android:normalScreens="true"
                      android:largeScreens="true" />
            <uses-sdk android:minSdkVersion="4"
              android:maxSdkVersion="10"/>

         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

         <uses-permission android:name="android.permission.INTERNET"></uses-permission>
         <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
         <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>


       </manifest> 
  • 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-18T03:30:45+00:00Added an answer on June 18, 2026 at 3:30 am

    Off by 1 error. Your for loop getting the views goes i<5, but you’re accessing i=5 with LINKSP. Increase your for loop and all arrays by 1.

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

Sidebar

Related Questions

Wondering if I could get some advice and direction on this following requirement: Need
I was wondering if i could get some help. What i am trying to
I was wondering if anyone could help me with getting this working. I'm using
I could use a set of eyes (or more) on this code. I'm trying
I need to do the following and i was wondering if i could get
I was wondering how could I reload any website using javascript and set it
Im just wondering how I could get the post id of the blog post
I know this was discussed many times, I am hoping to get an advice
I was wondering if I could somehow get some guidance on using QueryPerformanceCounter/Frequency on
Bashing my head against a wall here - was wondering if anybody could help

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.