Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用android将文件上载到服务器_Java_Android_File Upload - Fatal编程技术网

Java 使用android将文件上载到服务器

Java 使用android将文件上载到服务器,java,android,file-upload,Java,Android,File Upload,我正在使用下面的代码在服务器上上载文件。但每当我运行此代码时,我的应用程序都会意外关闭 代码: } php的代码是: <?php $file_path = "uploads/"; $file_path = $file_path . basename( $_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path))

我正在使用下面的代码在服务器上上载文件。但每当我运行此代码时,我的应用程序都会意外关闭

代码:

}

php的代码是:

<?php

    $file_path = "uploads/";

    $file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
        echo "success";
    } else{
        echo "fail";
    }
 ?>
我不知道如何,但它在关闭前上传了两个图像文件。 感谢您的帮助

    03-07 02:24:35.092: W/Resources(2847): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f050003}

03-07 02:24:35.252: D/dalvikvm(2847): GC_FOR_ALLOC freed 118K, 6% free 3265K/3448K, paused 40ms, total 45ms

03-07 02:24:35.382: D/(2847): HostConnection::get() New Host Connection established 0xb80e2ae0, tid 2847

03-07 02:24:35.482: W/EGL_emulation(2847): eglSurfaceAttrib not implemented

03-07 02:24:35.502: D/OpenGLRenderer(2847): Enabling debug mode 0

03-07 02:24:40.332: W/IInputConnectionWrapper(2847): showStatusIcon on inactive InputConnection

03-07 02:24:49.832: W/EGL_emulation(2847): eglSurfaceAttrib not implemented

03-07 02:24:50.872: I/Choreographer(2847): Skipped 60 frames!  The application may be doing too much work on its main thread.

03-07 02:24:51.612: D/dalvikvm(2847): GC_FOR_ALLOC freed 262K, 9% free 
3464K/3792K, paused 348ms, total 351ms

03-07 02:24:52.072: D/dalvikvm(2847): GC_FOR_ALLOC freed 6K, 9% free             3553K/3888K, paused 410ms, total 411ms

03-07 02:24:54.862: I/uploadFile(2847): HTTP Response is : OK: 200

03-07 02:24:55.112: D/AndroidRuntime(2847): Shutting down VM

03-07 02:24:55.122: W/dalvikvm(2847): threadid=1: thread exiting with uncaught exception (group=0xb1a97b90)

03-07 02:24:55.122: E/AndroidRuntime(2847): FATAL EXCEPTION: main

03-07 02:24:55.122: E/AndroidRuntime(2847): Process: com.example.fileuploaddemo, PID: 2847

03-07 02:24:55.122: E/AndroidRuntime(2847): java.lang.NullPointerException

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.content.ContextWrapper.getResources(ContextWrapper.java:89)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at     android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.widget.Toast.<init>(Toast.java:93)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.widget.Toast.makeText(Toast.java:241)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.example.fileuploaddemo.UploadToServer$9.run(UploadToServer.java:239)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Handler.handleCallback(Handler.java:733)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Handler.dispatchMessage(Handler.java:95)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Looper.loop(Looper.java:137)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.app.ActivityThread.main(ActivityThread.java:4998)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at java.lang.reflect.Method.invokeNative(Native Method)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at java.lang.reflect.Method.invoke(Method.java:515)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at dalvik.system.NativeStart.main(Native Method)

03-07 02:24:58.642: I/Process(2847): Sending signal. PID: 2847 SIG: 9

你能给我看一下崩溃日志吗?你得到了什么错误?你能邮寄吗logs@user3335496日志请它将需要时间来提供日志,因为我正在使用一个真正的设备进行测试。我将不得不寻找设置我的avd。如果通过usb与您的开发pc连接,真实设备也会产生logcat输出。
void openDialogBox()
{

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    startActivityForResult(intent, PICK_CONTACT_REQUEST);


}

protected void onActivityResult(int requestCode, int resultCode,
        Intent data) {
    if (requestCode == PICK_CONTACT_REQUEST) {
        if (resultCode == RESULT_OK) {
            // A contact was picked.  Here we will just display it
            // to the user.

            Uri uri =  data.getData();

            File file = new File(uri.toString());

            if(uri.toString().startsWith("file:/"))
                file = new File(uri.toString().substring(6));

            msgTxt.setText(file.getName());
            Toast.makeText(this, uri.toString(), Toast.LENGTH_SHORT).show();

            try
            {
                UploadToServer upToServer = new UploadToServer();
            upToServer.uploadToServer(file,msgTxt);
            }catch(Exception e)
            {
                msgTxt.setText(e.toString());
                e.printStackTrace();
            }


        }
    }
}
    03-07 02:24:35.092: W/Resources(2847): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f050003}

03-07 02:24:35.252: D/dalvikvm(2847): GC_FOR_ALLOC freed 118K, 6% free 3265K/3448K, paused 40ms, total 45ms

03-07 02:24:35.382: D/(2847): HostConnection::get() New Host Connection established 0xb80e2ae0, tid 2847

03-07 02:24:35.482: W/EGL_emulation(2847): eglSurfaceAttrib not implemented

03-07 02:24:35.502: D/OpenGLRenderer(2847): Enabling debug mode 0

03-07 02:24:40.332: W/IInputConnectionWrapper(2847): showStatusIcon on inactive InputConnection

03-07 02:24:49.832: W/EGL_emulation(2847): eglSurfaceAttrib not implemented

03-07 02:24:50.872: I/Choreographer(2847): Skipped 60 frames!  The application may be doing too much work on its main thread.

03-07 02:24:51.612: D/dalvikvm(2847): GC_FOR_ALLOC freed 262K, 9% free 
3464K/3792K, paused 348ms, total 351ms

03-07 02:24:52.072: D/dalvikvm(2847): GC_FOR_ALLOC freed 6K, 9% free             3553K/3888K, paused 410ms, total 411ms

03-07 02:24:54.862: I/uploadFile(2847): HTTP Response is : OK: 200

03-07 02:24:55.112: D/AndroidRuntime(2847): Shutting down VM

03-07 02:24:55.122: W/dalvikvm(2847): threadid=1: thread exiting with uncaught exception (group=0xb1a97b90)

03-07 02:24:55.122: E/AndroidRuntime(2847): FATAL EXCEPTION: main

03-07 02:24:55.122: E/AndroidRuntime(2847): Process: com.example.fileuploaddemo, PID: 2847

03-07 02:24:55.122: E/AndroidRuntime(2847): java.lang.NullPointerException

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.content.ContextWrapper.getResources(ContextWrapper.java:89)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at     android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.widget.Toast.<init>(Toast.java:93)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.widget.Toast.makeText(Toast.java:241)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.example.fileuploaddemo.UploadToServer$9.run(UploadToServer.java:239)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Handler.handleCallback(Handler.java:733)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Handler.dispatchMessage(Handler.java:95)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.os.Looper.loop(Looper.java:137)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at android.app.ActivityThread.main(ActivityThread.java:4998)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at java.lang.reflect.Method.invokeNative(Native Method)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at java.lang.reflect.Method.invoke(Method.java:515)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)

03-07 02:24:55.122: E/AndroidRuntime(2847):     at dalvik.system.NativeStart.main(Native Method)

03-07 02:24:58.642: I/Process(2847): Sending signal. PID: 2847 SIG: 9
Log.i("uploadFile", "HTTP Response is : " 
                       + serverResponseMessage + ": " + serverResponseCode);


               if(serverResponseCode == 200)
               {

                   runOnUiThread(new Runnable() {
                        public void run() {

                            String msg = "File Upload Completed.\n\n See uploaded file here : \n\n"
                                          +" http://www.androidexample.com/media/uploads/"
                                          +uploadFileName;

                            messageText.setText(msg);
                            Toast.makeText(UploadToServer.this, "File Upload Complete.", 
                                         Toast.LENGTH_SHORT).show();
                        }
                            });


               }