Attempted to finish an input event but the ~~~异常

这是报的错误:

04-8 06:36:48.372: W/InputEventReceiver(7867): Attempted to finish an input event but the input event receiver has already been disposed.
04-8 06:36:48.372: W/InputEventReceiver(7867): Attempted to finish an input event but the input event receiver has already been disposed.
04-8 06:36:48.372: I/Choreographer(7867): Skipped 87 frames!  The application may be doing too much work on its main thread.
04-8 06:36:48.372: W/ViewRootImpl(7867): Dropping event due to root view being removed: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=287.0, y[0]=-358.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=5442878, downTime=5442722, deviceId=0, source=0x1002 }
04-8 06:37:31.392: I/uploadFile(7867): HTTP Response is : Internal Server Error: 50001-18 06:37:31.522: E/Async Time(7867): Async entered POSTTTT

这是源码:

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

        private String webAddressToPost = "http://10.0.2.2:3000/wardrobe";

        // File sourceFile = new File(imageview);
        String fileName = "/sdcard/IMG_2016.JPG";
        File sourceFile = new File(fileName );

        HttpURLConnection conn = null;
        DataOutputStream dos = null;
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1 * 1024 * 1024;

        // private ProgressDialog dialog
        private ProgressDialog progressDialog = new ProgressDialog(
                wardrobe.this);

        @Override
        protected void onPreExecute() {
            Log.e("Async Time", "Async entered 1 PREEE");
            progressDialog.setMessage("Uploading...");
            progressDialog.show();
        }

        @Override
        protected String doInBackground(String... arg0) {
            Log.e("Async Time", "Async entered DURINGG");
            try {
                // open a URL connection to the Servlet
                FileInputStream fileInputStream = new FileInputStream(
                        sourceFile);
                URL url = new URL(webAddressToPost);

                // Open a HTTP connection to the URL
                conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true); // Allow Inputs
                conn.setDoOutput(true); // Allow Outputs
                conn.setUseCaches(false); // Don't use a Cached Copy
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("ENCTYPE", "multipart/form-data");
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);
                conn.setRequestProperty("uploaded_file", fileName);

                dos = new DataOutputStream(conn.getOutputStream());

                dos.writeBytes(twoHyphens + boundary + lineEnd);
                dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
                        + fileName + "\"" + lineEnd);

                dos.writeBytes(lineEnd);

                // create a buffer of maximum size
                bytesAvailable = fileInputStream.available();

                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                buffer = new byte[bufferSize];

                // read file and write it into form...
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                while (bytesRead > 0) {

                    dos.write(buffer, 0, bufferSize);
                    bytesAvailable = fileInputStream.available();
                    bufferSize = Math.min(bytesAvailable, maxBufferSize);
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                }

                // send multipart form data necesssary after file data...
                dos.writeBytes(lineEnd);
                dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                // Responses from the server (code and message)
                serverResponseCode = conn.getResponseCode();
                String serverResponseMessage = conn.getResponseMessage();

                Log.i("uploadFile", "HTTP Response is : "
                        + serverResponseMessage + ": " + serverResponseCode);

                if (serverResponseCode == 200) {

                    String msg = "File Upload Completed.\n\n See uploaded file here : \n\n"
                            + " F:/wamp/wamp/www/uploads";
                    imageTextSelect.setText(msg);
                    Toast.makeText(wardrobe.this, "File Upload Complete.",
                            Toast.LENGTH_SHORT).show();

                }

                // close the streams //
                fileInputStream.close();
                dos.flush();
                dos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            Log.e("Async Time", "Async entered POSTTTT");
            progressDialog.dismiss();
            Toast.makeText(getApplicationContext(), "file uploaded",
                    Toast.LENGTH_LONG).show();
        }
    }

解决办法:

将String fileName = "/sdcard/IMG_2016.JPG"; 改为:

String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + 
                            "/IMG_2016.JPG";







转载于:https://my.oschina.net/u/1244156/blog/220393

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值