无法解析符号'执行',android studio 8.0 beta

时间:2014-06-29 13:51:23

标签: java android maven android-studio asynchttpclient

我知道很多人都有类似我的问题,但我找到的答案似乎没有用。

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 beta

1 个答案:

答案 0 :(得分:1)

删除此行中的new

HttpResponse httpr = new httpc.execute(httpp);

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