我是新手,我在学Android

今天遇到的问题:

写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 ! 官方有点误导我了!

posted @ 2012-03-30 02:52  ifeixiang  阅读(626)  评论(0编辑  收藏  举报