无法解析符号执行,android

时间:2017-09-15 14:42:57

标签: android crud httpconnection

我正在尝试设置我的应用程序以与服务器通信,以便我可以执行配置文件crud。我设置了一个工厂,当点击它将创建一个JSONObject并将该数据发布到服务器时,所有代码似乎都没问题,但在“new SendUserDetails.execute(”server_URL“,postData.toString());”说它无法解析符号执行。有没有我忽略的东西?非常感谢您的帮助。

edit_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            JSONObject postData = new JSONObject();
            try{
                postData.put("Name", name.getText().toString());
                postData.put("Bio", bio.getText().toString());
                postData.put("Age", age.getText().toString());
                postData.put("Major", major.getText().toString());
                postData.put("College", college.getText().toString());
                postData.put("Random Fact", random_fact.getText().toString());

                new SendUserDetails.execute("server_URL", postData.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

这是Http连接的代码

private class SendUserDetails extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... params) {
        String data = "";

        HttpURLConnection httpURLConnection = null;
        try{
            httpURLConnection = (HttpURLConnection) new URL(params[0]).openConnection();
            httpURLConnection.setRequestMethod("POST");

            httpURLConnection.setDoOutput(true);

            DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
            wr.writeBytes("PostData" + params[1]);
            wr.flush();
            wr.close();

            InputStream in = httpURLConnection.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(in);

            int inputStreamData = inputStreamReader.read();
            while(inputStreamData != -1){
                char current = (char) inputStreamData;
                inputStreamData = inputStreamReader.read();
                data += current;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(httpURLConnection != null){
                httpURLConnection.disconnect();
            }
        }
        return data;
    }

    @Override
    protected void onPostExecute(String result){
        super.onPostExecute(result);
        Log.e("TAG", result);
    }
}

1 个答案:

答案 0 :(得分:0)

SendUserDetails之后添加parens,因为您正在尝试调用构造函数。换句话说,将new SendUserDetails.execute(...)替换为new SendUserDetails().execute(...)