I know many people have issues like mine, but the answers I found didn't seem to work.
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;
}
}
`
As you can see in this code, I used the HttpClient.execute command, but Android studio refers to .execute command as an error: cannot resolve symbol 'execute'
.
I have already tried Invalidating Cache and restart. I also turned on Maven's auto import check box.
OS: win7 32-bit JDK: jdk7(Java EE) Android Studio: 8.0 beta