Jeff Thomas
Jeff Thomas

Reputation: 4816

Android NameValuePair not Accepting String

I am using HTTPPost to send values to a server. The script works fine with what I have below. However if I change the name value pair to this I get a force close:

nameValuePairs.add(new BasicNameValuePair("id", idOfTextView.getText().toString()));

This is the code without it reading the textview:

 String url_select = "http://mydomain.com/get.php";
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url_select);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("id", "1"));
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        //read content
        is =  httpEntity.getContent();                  
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection "+e.toString());
    }

    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = "";
        while((line=br.readLine())!=null){
            sb.append(line+"\n");
        }
        is.close();
        result=sb.toString();               
    } catch (Exception e) {
        Log.e("log_tag", "Error converting result "+e.toString());
    }
    return null;

Upvotes: 1

Views: 705

Answers (1)

wsanville
wsanville

Reputation: 37516

Looks like my comment was the answer, make sure idOfTextView is non-null.

Upvotes: 1

Related Questions