0

Screenshot 1

Screenshot 2

How to solve this, help me out I'm new

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
DjRaf
  • 3
  • 4

2 Answers2

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...

  • 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'm new I dnt knw how to do this – DjRaf Feb 28 '16 at 17:30
  • 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
  • Open your gradle file (there are two) and look for this: – Jordy Cuan Feb 28 '16 at 17:57
  • 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
  • Add this: 'org.apache.httpcomponents:httpclient:4.0-alpha4' – Jordy Cuan Feb 28 '16 at 18:19
  • hmm, try this: compile 'org.apache.httpcomponents:httpclient:4.5' – Jordy Cuan Feb 28 '16 at 19:14
  • 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