NameValuePair不接受字符串

NameValuePair不接受字符串

我正在使用HTTPPost将值发送到服务器。该脚本可以很好地与下面的内容兼容。但是,如果我将名称值对更改为此,则会强制关闭:

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


这是没有阅读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;

最佳答案

看来我的评论就是答案,请确保idOfTextView不为空。

关于android - Android NameValuePair不接受字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11041962/

10-09 21:05