今天遇到的问题:

写WIFI应用的时候看到Android官方开发文档上写着Context.getSystemService(Context.WIFI_SERVICE).以为直接可以用,可是总是提示Cannot make a static reference to the non-static method getSystemService(String) from the type Context , 搞得我甚是郁闷,原来是这个Context没有实例对象,

我测试的时候是这样用的:

public void connect()
{
     WifiManager wifiManager =    Context.getSystemService(Context.WIFI_SERVICE).
}

 So,错了!

   这里的Context应该上传进来的Activity,所以应该这样用:

 

public void connect(Context context)
{
     WifiManager wifiManager =    context.getSystemService(Context.WIFI_SERVICE).
}

  注意前后context变量 和 Context.WIFI_SERIVCE ! 官方有点误导我了!

相关文章:

  • 2021-05-01
  • 2021-06-19
  • 2021-10-02
  • 2021-12-02
  • 2021-12-14
  • 2021-09-24
  • 2021-07-09
猜你喜欢
  • 2021-07-22
  • 2021-08-18
  • 2022-01-12
  • 2021-12-23
  • 2022-01-01
  • 2021-10-01
  • 2021-09-03
相关资源
相似解决方案