Java 无法在返回类型中解析Android Eclipse上下文

Java 无法在返回类型中解析Android Eclipse上下文,java,android,eclipse,class,Java,Android,Eclipse,Class,我在理解上下文方面有困难,我写了一个程序来控制我的灯光,但我需要检查他是否连接了错误的WiFi,然后使用了错误的IP。我尝试了多种选择,但没有一个好的解决方案。我看了看前面几个关于上下文省略成功的问题。如果您需要完整的程序,我可以将其发送给您,但我认为这足够代码:) 确切的问题在于getCurrentSsid(上下文)错误:无法在返回类型中解析上下文 //CLASS SENDCOMMAND public class SendCommand extends AsyncTask<String

我在理解上下文方面有困难,我写了一个程序来控制我的灯光,但我需要检查他是否连接了错误的WiFi,然后使用了错误的IP。我尝试了多种选择,但没有一个好的解决方案。我看了看前面几个关于上下文省略成功的问题。如果您需要完整的程序,我可以将其发送给您,但我认为这足够代码:)

确切的问题在于getCurrentSsid(上下文)错误:无法在返回类型中解析上下文

//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)
//类SENDCOMMAND
公共类SendCommand扩展了异步任务{
静态布尔WifiSSID;
公共发送命令(布尔wifi){
this.wifi=wifi;
}
//用于检查当前SSID的函数
公共布尔getCurrentSsid(上下文){
ssid=null;
ConnectivityManager connManager=(ConnectivityManager)context.getSystemService(context.CONNECTIVITY_服务);
NetworkInfo NetworkInfo=connManager.getNetworkInfo(ConnectivityManager.TYPE\u WIFI);
if(networkInfo.isConnected()){
最终WifiManager=(WifiManager)context.getSystemService(context.WIFI_服务);
final WifiInfo connectionInfo=wifiManager.getConnectionInfo();
if(connectionInfo!=null&&!TextUtils.isEmpty(connectionInfo.getSSID()){
ssid=connectionInfo.getSSID();
}
}
如果(ssid=“房间2”)
返回true;
其他的
返回false;
}
//wifiSSID=布尔getCurrentSsid(上下文);
//发出命令
@凌驾
受保护的JSONArray doInBackground(字符串…参数){
//TODO自动生成的方法存根
Log.d(标记为“背景中的Beginnen do”);
日志d(标签“Wifi为”+Wifi);
HttpClient=new DefaultHttpClient();
HttpGet;
如果(wifi&&**getCurrentSsid(上下文)**){//这里他给出了一个错误getCurrentSsid(上下文)

在您的
doInBackground
范围内没有名称为
context
的符号

上下文
传递给异步任务的常见方法是将其存储在成员变量中,然后将其传递到构造函数arg中:

private Context mContext;

public SendCommand(Context context) {
    mContext = context;
}

然后在需要上下文的地方使用
mContext

对不起,我编辑了它。上下文变量设置在哪里?我以前试过这个!Eclipse没有给出错误,但当我按下按钮打开灯时,我的应用程序不断停止…09-22 17:51:45.628:W/dalvikvm(15218):threadid=11:thread退出时出现未捕获异常(group=0x40ea76d8)我没有看到错误?开始调试stacktrace崩溃..另请查看