2016-06-01 5 views
0

Ich habe Suche nach Lösungen für öffnen fehlgeschlagen: ENOENT (keine solche Datei oder Verzeichnis) Fehler, aber haben alles müde und funktioniert immer noch nicht.öffnen fehlgeschlagen: ENOENT mit getAbsolutePath()

Ich versuche, die Bilder auf meinem Handy in eine Datenbank hochzuladen, die ich auf einem Server erstellt habe.

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)  

Das ist die Fehlermeldung, die ich bekomme.

Dies ist der Code, den ich ausführen, um die getAbsolutePath() zu überprüfen;

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); 
     } 
    } 

Antwort

0
File myFile = new File(selectedImageURI.getPath()); 

Wenn Sie getPath() auf einem Uri nennen, tun Sie es falsch, es sei denn, dass Uri ein file Schema hat. Ihr Uri hat ein content Schema. Eine solche Uri muss nicht auf eine Datei im Dateisystem verweisen, von der Sie lesen können.

Verwenden ContentResolver und openInputStream() ein InputStream auf dem Inhalt durch die Uri dargestellt zu öffnen. Dann benutze das mit was auch immer UploadFileAsync tut.

0

Achten Sie auf die übergeordnete Verzeichnisse zuerst erstellen:

myFile.mkdirs(); 
Verwandte Themen