[英]Android Eclipse context cannot be resolved in return type
I have problems understanding Context I write a program to control my light, but I need to check if he doesn't connect the wrong WiFi and then use a wrong IP. 我在理解上下文时遇到问题,我编写了一个控制灯光的程序,但是我需要检查他是否没有连接错误的WiFi,然后使用错误的IP。 I try multiple options without a good solution. 我没有很好的解决方案尝试多种选择。 I look to a few earlier question about context whiteout success. 我期待一些有关上下文清除成功的较早问题。 If you need the full program I can send it to you, but I think this is enough code:) 如果您需要完整的程序,我可以将其发送给您,但是我认为这已经足够了:)
The exact problem is by getCurrentSsid(context) error: context cannot be resolved in return type 确切的问题是由于getCurrentSsid(context) 错误:无法在返回类型中解析上下文
//CLASS SENDCOMMAND
public class SendCommand extends AsyncTask<String, Integer, JSONArray> {
static boolean WifiSSID;
public SendCommand(boolean wifi) {
this.wifi = wifi;
}
//FUNCTION TO CHECK THE CURREN SSID
public boolean getCurrentSsid(Context context) {
ssid = null;
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) {
ssid = connectionInfo.getSSID();
}
}
if (ssid =="Room#2")
return true;
else
return false;
}
//wifiSSID = boolean getCurrentSsid(context);
//send the command
@Override
protected JSONArray doInBackground(String... params) {
// TODO Auto-generated method stub
Log.d(tag, "Beginnen do in background");
Log.d(tag, "Wifi is " + wifi);
HttpClient client = new DefaultHttpClient();
HttpGet get;
if (wifi && **getCurrentSsid(context)**){ //HERE HE GIVES A ERROR getCurrentSsid(context)
There's no symbol with the name context
in scope in your doInBackground
. 在doInBackground
context
,范围内没有带名称context
符号。
A common way to pass a Context
to an async task is to store it in a member variable and pass it in in an constructor arg: 将Context
传递给异步任务的一种常见方法是将其存储在成员变量中,然后将其传递给构造函数arg:
private Context mContext;
public SendCommand(Context context) {
mContext = context;
}
and then use mContext
where a Context
is needed. 然后在需要Context
地方使用mContext
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.