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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:44:35+00:00 2026-06-07T14:44:35+00:00

So I am quite new to Android, and have limited previous Java experience, so

  • 0

So I am quite new to Android, and have limited previous Java experience, so please bear with me. I am trying to create an object of type WifiManager in an Android App, and I have the line I found several other people recommend to create a WifiManager object verbatum:

WifiManager wifi =  mContext.getSystemService(Context.WIFI_SERVICE);

in my program. Now Eclipse has underlined the mContext.GetSystemService etc part with the error Type mismatch, cannot convert from object to WifiManager

Now I have tried recasting the return using:

(WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

This will compile, but results in a java.lang.NullPointerException when executed

Any thoughts on this would be greatly appreciated!

UPDATE*

SO I have setup the

Context mContext; 

in my main class

Then I am trying to use a broadcast to find the address of a SQL server on my network. The code is kinda messy since I am just in the phase where I am trying to get just transmitting the broadcast to work. But here is the function.

public void findSQL()
{
    int PORT = 1433;

    try
    {
        byte buff[] = new byte[1024];
        DatagramSocket sock = new DatagramSocket(PORT); 
        sock.setBroadcast(true);

        // Create and send the broadcast packet
        DatagramPacket dp = new DatagramPacket(buff, 7, getBroadcastAddress(), PORT);

        sock.send(dp);

        DatagramPacket dp1 = new DatagramPacket(buff, buff.length);

        sock.receive(dp1);

        sock.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
InetAddress getBroadcastAddress() throws IOException {  
    WifiManager wifi =  (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    System.out.println(dhcp.toString());

    if(dhcp==null)
        return InetAddress.getByAddress(null);

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;

    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
    {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return InetAddress.getByAddress(quads);
}

SECOND EDIT*

Earlier in my code I have defined:

    @SuppressWarnings("unused")
class MSSQL_DB
{
    Context mContext;
    public void dbConnect(String db_connect_string, 
            String db_userid, String db_password)
    {
        try
        {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            Connection conn = DriverManager.getConnection(db_connect_string,
                    db_userid, db_password);
            System.out.println("Connected");

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

I am afraid the whole concept of what “context” actually does, how to declare it correctly, and how to use its methods is what I must not be fully understanding yet.

  • 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-07T14:44:36+00:00Added an answer on June 7, 2026 at 2:44 pm

    Most probably ur mContext is null.. If not

    Please post more logs of exception.. and post more code …

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

Sidebar

Related Questions

I'm quite new in Java android development. So I have an issue with my
I'm quite new to Android development. My understanding is that you can create several
First of all, I'm quite new to the Android and JAVA world (coming from
I am quite new to Java and am currently coding an Android application. In
I'm new to android. I have some java knowledge (not extensive), and I've done
Alright, so I'm new to Android programming, so far my experience has been quite
I am quite new to Android dev, but not Java dev, so doing the
[I'm quite new with Android programming so please excuse me for my nooby questions]
I'm quite new to Android and I have been reading the Professional Android 2
I'm quite new to android, but I have already created several apps and published,

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.