How to solve this, help me out I'm new
Asked
Active
Viewed 68 times
2 Answers
1
Please explain your question... If you want to fetch from http, below code will help you. you may need to add some libraries too.
HttpClient httpclient = new DefaultHttpClient();
Httppost httppost = new HttpPost("www.example.com");
HttpResponse response = httpclient.execute(httppost);
entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String result = sb.toString();
JSONObject jsonObj = new JSONObject(result);
continue your code after this...

Prashant Rahate
- 163
- 10
-
I was following a tutorial , [link](http://www.wingnity.com/blog/android-json-parsing-and-image-loading-tutorial/) see this I did the same but , I'm getting import errore – DjRaf Feb 28 '16 at 17:56
0
Add the libraries to the gradle file.
Look for this line:
dependencies {
...
}
and add this:
dependencies {
...
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.apache.httpcomponents:httpcore:4.4'
}

Jordy Cuan
- 467
- 6
- 13
-
-
I jxt want to make a connection Imdoing json parsing , jxt this Http thing is remaining – DjRaf Feb 28 '16 at 17:31
-
Can you show me your imports in that Java file? Did you write that code or is it copy-paste? – Jordy Cuan Feb 28 '16 at 17:34
-
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; – DjRaf Feb 28 '16 at 17:53
-
and yes I following a tutorial , I was doing the samebut in end I got these , import error I dnt knw why – DjRaf Feb 28 '16 at 17:53
-
-
compile { ... } add this inside 'org.apache.httpcomponents:httpcore:4.4' – Jordy Cuan Feb 28 '16 at 17:57
-
You can see an example here: https://github.com/juleswhite/mobilecloud-15/blob/master/assignments/assignment2/build.gradle – Jordy Cuan Feb 28 '16 at 18:03
-
import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; – DjRaf Feb 28 '16 at 18:13
-
-
-
if that does not work then you can read this: http://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studio – Jordy Cuan Feb 28 '16 at 19:15