wj198524 2023-03-05 16:04 采纳率: 100%
浏览 33
已结题

java编译时提示错误:找不到符,如何解决?

****错误: 找不到符号
new StringBody(params.get(index).getValue(),
^
符号: 类 StringBody




```public String submit_Data(String uid, String picpath, String url) {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("image", picpath));
            params.add(new BasicNameValuePair("uid", uid));
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url);
            try {
                MultipartEntity entity = new MultipartEntity(
                        HttpMultipartMode.BROWSER_COMPATIBLE);
                for (int index = 0; index < params.size(); index++) {
                    if (params.get(index).getName().equalsIgnoreCase("image")) {
                        System.out.println("post - if");
                        entity.addPart(params.get(index).getName(),
                                new FileBody(new File(params.get(index)
                                        .getValue())));
                    } else {
                        entity.addPart(params.get(index).getName(),
                                  new StringBody(params.get(index).getValue(),
                                        Charset.forName("UTF-8")));
                    }
                }
                httpPost.setEntity(entity);
                HttpResponse response = httpClient.execute(httpPost,
                        localContext);
                responsecode = response.getStatusLine().getStatusCode();
                if (responsecode == 200) {
                    HttpEntity resEntity = response.getEntity();
                    String Response = EntityUtils.toString(resEntity);
                    return Response;
                }
            } catch (Exception e) {
                return "";
            }
            return "";
        }
    }
  • 写回答

4条回答 默认 最新

  • Huazie 全栈领域优质创作者 2023-03-05 16:39
    关注

    StringBody 这个类你导入了嘛,检查一下

    Charset 这个也需要导入

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 3月13日
  • 已采纳回答 3月5日
  • 修改了问题 3月5日
  • 创建了问题 3月5日