You create a TextView in onPostExecute() but you don't do anything with it. It's not added to the activity.
On Thu, Jul 9, 2009 at 7:27 PM, Persona<[email protected]> wrote: > > hi, the code below was designed to display text within android (this > is a response from the web server). But somehow the code doesn't work- > looking at it I don't see any problem, and there are no errors > reported. The application runs and no code is displayed. > > Can somebody with greater experience uncover any problem within the > program? > > package http.client; > > import java.io.BufferedReader; > import java.io.IOException; > import java.io.InputStreamReader; > import java.io.UnsupportedEncodingException; > import java.net.URL; > import java.util.ArrayList; > import java.util.List; > > import org.apache.http.HttpResponse; > import org.apache.http.NameValuePair; > import org.apache.http.client.ClientProtocolException; > 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 org.apache.http.message.BasicNameValuePair; > > import android.app.Activity; > import android.os.AsyncTask; > import android.os.Bundle; > import android.view.View; > import android.widget.TextView; > import android.widget.Toast; > > public class TestHttpClient extends Activity > { > @Override > public void onCreate(Bundle icicle){ > super.onCreate(icicle); > setContentView(R.layout.main); > new HttpConnect1().execute(); > } > > private class HttpConnect1 extends AsyncTask<String, Void, Void> > { > String result; > �...@override > protected Void doInBackground(String...strings) > { > BufferedReader in = null; > try { > HttpClient client = new DefaultHttpClient(); > HttpPost request = new > HttpPost("http://www.cnn.com"); > List<NameValuePair> postParameters = new > ArrayList<NameValuePair> > (); > postParameters.add(new > BasicNameValuePair("one", > "valueGoesHere")); > UrlEncodedFormEntity formEntity = null; > try { > formEntity = new > UrlEncodedFormEntity(postParameters); > } catch (UnsupportedEncodingException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > request.setEntity(formEntity); > HttpResponse response = > client.execute(request); > in = new BufferedReader(new > InputStreamReader(response.getEntity > ().getContent())); > StringBuffer sb = new StringBuffer(""); > String line = ""; > String NL = > System.getProperty("line.separator"); > while ((line = in.readLine()) != null) { > sb.append(line + NL); > } > in.close(); > result = sb.toString(); > > } catch (Exception e) { > e.printStackTrace(); > } finally > { > if (in != null) { > try { > in.close(); > } catch (IOException e) { > e.printStackTrace(); > } > } > } > return null; > } > //@Override > protected void onPostExecute(String result) > { > TextView tv = new TextView(TestHttpClient.this); > tv.setText(result); > } > } > > } > > > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

