0

open failed: ENOENT (No such file or directory) エラーの解決策を検索しましたが、すべてが疲れていて、まだ機能しません。

サーバー上に作成したデータベースに携帯電話の写真をアップロードしようとしています。

06-01 15:59:32.631 25399-26074/com.example.vikhram.projectv E/Debug: error: /document/primary:Pictures/Pic0601_14Lat_65.6172057.jpeg: open failed: ENOENT (No such file or directory)
                                                                 java.io.FileNotFoundException: /document/primary:Pictures/Pic0601_14Lat_65.6172057.jpeg: open failed: ENOENT (No such file or directory)
                                                                     at libcore.io.IoBridge.open(IoBridge.java:452)
                                                                     at java.io.FileInputStream.<init>(FileInputStream.java:76)
                                                                     at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:406)
                                                                     at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:375)
                                                                     at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                     at java.lang.Thread.run(Thread.java:818)
                                                                  Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                                     at libcore.io.Posix.open(Native Method)
                                                                     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                                                                     at libcore.io.IoBridge.open(IoBridge.java:438)
                                                                     at java.io.FileInputStream.<init>(FileInputStream.java:76) 
                                                                     at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:406) 
                                                                     at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:375) 
                                                                     at android.os.AsyncTask$2.call(AsyncTask.java:295) 
                                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                     at java.lang.Thread.run(Thread.java:818) 
06-01 15:59:32.631 25399-26074/com.example.vikhram.projectv E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                                                                          Process: com.example.vikhram.projectv, PID: 25399
                                                                          java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                              at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                                              at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                              at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                              at java.lang.Thread.run(Thread.java:818)
                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream java.net.HttpURLConnection.getInputStream()' on a null object reference
                                                                              at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:459)
                                                                              at com.example.vikhram.projectv.MainActivity$UploadFileAsync.doInBackground(MainActivity.java:375)
                                                                              at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                              at java.lang.Thread.run(Thread.java:818) 

それが私が得るエラーメッセージです。

これは、getAbsolutePath(); をチェックするために実行するコードです。

if (requestCode == READ_REQUEST_CODE && resultCode == RESULT_OK) {
        // The document selected by the user won't be returned in the intent.
        // Instead, a URI to that document will be contained in the return intent
        // provided to this method as a parameter.
        // Pull that URI using resultData.getData().
        //Uri uri = null;
        if (data != null) {
            //super.onActivityResult(requestCode, resultCode, data);
            Uri selectedImageURI = data.getData();
           File myFile = new File(selectedImageURI.getPath());
            //File myFile = new File(data.getData().toString());
            //File imageFile = new File(getRealPathFromURI(selectedImageURI));
            //new UploadFileAsync().execute(myFile.getAbsolutePath().toString());
            new UploadFileAsync().execute(myFile.getAbsolutePath().toString());
            //Log.i(TAG, "Uri: " + selectedImageURI.toString());
            //showImage(uri);
        }
    }
4

2 に答える 2

0

最初に親ディレクトリを作成してください。

myFile.mkdirs();
于 2016-06-01T16:53:12.637 に答える
0
File myFile = new File(selectedImageURI.getPath());

を呼び出す場合getPath()、スキームがUriない限り、間違っています。あなたには計画があります。そのような aが、読み取り可能なファイルシステム上のファイルを指す必要はありません。UrifileUricontentUri

ContentResolverとを使用して、で表されるコンテンツopenInputStream()の を開きます。次に、それを何でも使用します。InputStreamUriUploadFileAsync

于 2016-06-01T14:14:43.770 に答える