public String getMacInfo(){
String mac = "";
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo.getMacAddress()!=null){
mac = wifiInfo.getMacAddress();
} else {
mac = "Fail";
}
return mac;
}
我在我的测试用例中添加了这些代码,有一个错误
在"mContext"中显示第3行。
谁能帮我??"mContext cannot be resolved"错误表示变量"mContext"不在作用域中(或者没有在任何地方声明)。
修复方法很简单,只需要将对象声明为成员变量,并在setUp()方法中初始化它。
public class MyTest extends InstrumentationTestCase {
private Context mContext;
public void setUp() {
mContext = getInstrumentation().getContext();
}
// ...
}
参见Java,"变量名";对于关于此特定错误的类似问题,无法解析为变量