Android droidscanner应用程序显示WifiManager getsystemservice类错误

Android droidscanner应用程序显示WifiManager getsystemservice类错误,android,android-asynctask,wifimanager,Android,Android Asynctask,Wifimanager,我正在开发一个网络扫描仪应用程序,它在IpScanActivity中的AsyncTask上给了我WifiManager类和方法getSystemService方法的错误。我在主要活动中使用了相同的类,没有问题,但当我在IpScanActivity上再次使用它时,它是在抱怨。我想将WifiInfo从main活动传递到IpScanActivity,但还没有找到方法。我想通过实例化IpScanactivity(不知道这是否是实现它的方法)无论如何。为什么我要在IpScanActivity上获得getS

我正在开发一个网络扫描仪应用程序,它在IpScanActivity中的AsyncTask上给了我WifiManager类和方法getSystemService方法的错误。我在主要活动中使用了相同的类,没有问题,但当我在IpScanActivity上再次使用它时,它是在抱怨。我想将WifiInfo从main活动传递到IpScanActivity,但还没有找到方法。我想通过实例化IpScanactivity(不知道这是否是实现它的方法)无论如何。为什么我要在IpScanActivity上获得getSystemService。提前谢谢。 主要活动

public class MainActivity extends AppCompatActivity {

    Button btnReadNet;
    TextView textResult;
    ListView listViewNode;
    ArrayList<String> networkList;
    ArrayAdapter<String> adapterNet;
    public String ip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnReadNet = (Button) findViewById(R.id.read_network);
        textResult = (TextView) findViewById(R.id.result);
        listViewNode = (ListView) findViewById(R.id.nodelist);
        networkList = new ArrayList<>();

        adapterNet = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, networkList);
        listViewNode.setAdapter(adapterNet);

        WifiManager wifiMan = (WifiManager) getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMan.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        ip  = String.format("%d.%d.%d.%d", (ipAddress & 0xff),(ipAddress >> 8 & 0xff),(ipAddress >> 16 & 0xff),(ipAddress >> 24 & 0xff));
        textResult.setText(printOutput(wifiInfo));



        //starting network scanner activity on button press
        btnReadNet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent scanNetIntent = new Intent(MainActivity.this, IpScanActivity.class);
                startActivity(scanNetIntent);
            }
        });
    }

    public String printOutput(WifiInfo wifiInfo) {
        return "Local IP: " + ip + "\n" +
                "SSID: " + wifiInfo.getSSID() + "\n" +
                "BSSID: " + wifiInfo.getBSSID() + "\n" +
                "MAC: " + wifiInfo.getMacAddress() + "\n" +
                "Signal: " + wifiInfo.getRssi() + "db" + "\n" +
                "Speed: " + wifiInfo.getLinkSpeed() + "Mbps" + "\n" +
                "Frequency: " + wifiInfo.getFrequency() + "MHz" + "\n" +
                "Connection: " + wifiInfo.getSupplicantState();
    }
}
nodedapter类

public class NodeAdapter extends ArrayAdapter<Node>{

    public NodeAdapter(Context context, int num, ArrayList<Node> allHost) {
        super(context, 0, allHost);
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        Node host = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
        }
        // Lookup view for data population
        TextView nodeIpTxtView = (TextView) convertView.findViewById(R.id.node_ip);
        TextView nodeMacTxtView = (TextView) convertView.findViewById(R.id.node_mac);
        // Populate the data into the template view using the data object
        nodeIpTxtView.setText(host.getIp());
        nodeMacTxtView.setText(host.getMac());
        // Return the completed view to render on screen
        return convertView;
    }
}
公共类NodeAdapter扩展了ArrayAdapter{
公共nodedapter(上下文上下文,int num,ArrayList allHost){
super(上下文,0,allHost);
}
@非空
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//获取此职位的数据项
节点主机=getItem(位置);
//检查是否正在重用现有视图,否则会膨胀视图
if(convertView==null){
convertView=LayoutInflater.from(getContext()).flate(R.layout.list_项,父项,false);
}
//数据填充的查找视图
TextView nodeIpTxtView=(TextView)convertView.findViewById(R.id.node_ip);
TextView nodeMacTxtView=(TextView)convertView.findViewById(R.id.node_mac);
//使用数据对象将数据填充到模板视图中
nodeIpTxtView.setText(host.getIp());
nodeMacTxtView.setText(host.getMac());
//返回要在屏幕上渲染的已完成视图
返回视图;
}
}
public class Node {
    String ip;
    String mac;
    String CanonicalHostName;
    String HostName;
    String remark;
    boolean isReachable;

    Node(String ip){
        this.ip = ip;
        //this.mac = mac;
        this.isReachable = true;
    }

    public String getIp() {
        return ip;
    }

    public String getHostName() {
        return HostName;
    }

    public String getMac() {
        return mac;
    }

    public String getRemark() {
        return remark;
    }

    public boolean isReachable() {
        return isReachable;
    }

    @Override
    public String toString() {
        return "IP: " + ip + "\n" +
                "MAC: " + mac + "\n" +
                "CanonicalHostName:\t" + CanonicalHostName + "\n" +
                "HostName:\t" + HostName + "\n" +
                "isReachable: " + isReachable +
                "\n" + remark;
    }

    private void queryHost(){
        try {
            InetAddress inetAddress = InetAddress.getByName(ip);
            CanonicalHostName = inetAddress.getCanonicalHostName();
            HostName = inetAddress.getHostName();

        } catch (UnknownHostException e) {
            e.printStackTrace();
            remark = e.getMessage();
        } catch (IOException e) {
            e.printStackTrace();
            remark = e.getMessage();
        }
    }
}
public class NodeAdapter extends ArrayAdapter<Node>{

    public NodeAdapter(Context context, int num, ArrayList<Node> allHost) {
        super(context, 0, allHost);
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        Node host = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
        }
        // Lookup view for data population
        TextView nodeIpTxtView = (TextView) convertView.findViewById(R.id.node_ip);
        TextView nodeMacTxtView = (TextView) convertView.findViewById(R.id.node_mac);
        // Populate the data into the template view using the data object
        nodeIpTxtView.setText(host.getIp());
        nodeMacTxtView.setText(host.getMac());
        // Return the completed view to render on screen
        return convertView;
    }
}