【问题标题】:Cannot Resolve Symbol 'execute', android studio 8.0 beta无法解析符号“执行”,android studio 8.0 beta
【发布时间】:2014-06-29 13:51:23
【问题描述】:

我知道很多人都有我这样的问题,但我找到的答案似乎不起作用。

import android.os.AsyncTask;



import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Created by DJ on 6/29/2014.
 */
public class RetrieveTask extends AsyncTask<String, Void, String> {

    protected String doInBackground(String... values){
        String result;
        try{
            ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
            HttpClient httpc = new DefaultHttpClient();
            HttpPost httpp = new HttpPost("http://" + values[0] + "/AndroidConnection/Select.php");
            httpp.setEntity(new UrlEncodedFormEntity(nvp));
            HttpResponse httpr = new httpc.execute(httpp);
            HttpEntity httpe = httpr.getEntity();
            InputStream is = httpe.getContent();

            BufferedReader br = new BufferedReader(new InputStreamReader(is, "iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;

            while((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result = sb.toString();

        } catch(Exception e){
            return e.getMessage();
        }

        return result;
    }

}
`

正如您在这段代码中看到的,我使用了 HttpClient.execute 命令,但 Android Studio 将 .execute 命令称为错误:cannot resolve symbol 'execute'

我已经尝试过使缓存失效并重新启动。我还打开了 Maven 的自动导入复选框。

操作系统:win7 32 位 JDK:jdk7(Java EE) Android Studio:8.0 测试版

【问题讨论】:

  • 你能发布完整的错误输出而不是cannot resolve symbol.....

标签: java android maven android-studio asynchttpclient


【解决方案1】:

删除此行中的new

HttpResponse httpr = new httpc.execute(httpp);

您不必创建新对象。你只会调用方法execute

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2013-11-15
    相关资源
    最近更新 更多