2

2 つのファイルを追加すると、次のmultipartentityメッセージが表示されます。

07-03 11:37:22.465: W/System.err(1112): java.io.FileNotFoundException: /: オープンに失敗しました: EISDIR (ディレクトリです)

同じ名前のディレクトリがある場合に発生する可能性がありますが、ここではそうではありません。

07-03 11:37:21.535: D/FilePath(1112): /mnt/sdcard/947808.jpg 07-03 11:37:21.535: D/FilePath(1112): /mnt/sdcard/126467-jugra.jpg

このような例外を修正するにはどうすればよいですか?

以下に示すように、次のコードがあります。

protected JSONObject doInBackground(String... params) {
            JSONObject json1 = null;
            JSONParser u = new JSONParser();
            photos = new ArrayList<String>();
            photos.add(photo1);
            photos.add(photo2);
            photos.add(photo3);
            List<File> f = new ArrayList<File>();

            for(String p:photos){
                Log.d("FilePath",p);
                if (p.equals("")|| p.equals("empty"))f.add(new File(p));
            }

            json1 = u.getJSONFromUrl(f);
            photos.clear();
            return json1;
        }
    public JSONObject getJSONFromUrl(List<File> f) {
        if (isOnline()) {

            String u = url;
            u = u + "?";
            try {
                // defaultHttpClient

                httpClient = HttpClientFactory.getThreadSafeClient();
                HttpPost httpPost = new HttpPost(url);
                MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                multipartEntity.addPart("action", new StringBody("upload_api"));
                for(File fs:f){
                    multipartEntity.addPart("photo_api[]", new FileBody(fs));
                }
//              
                httpPost.setEntity(multipartEntity);
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
                Log.d("data is sent", "true");

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                return null;

            }
            Log.d("wait", "true");
            try {
                Log.d("response","response");
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    // Log.d("JSON line", line);
                    sb.append(line + "\n");
                }
                is.close();
                json = sb.toString();
                Log.d("JSON", json);
                if (json.contains("error:2")) {
                    return null;
                }
                try {
                    jObj = new JSONObject(json);
                } catch (JSONException e) {
                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                    return null;
                }
//              pd.dismiss();
                return jObj;

            } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
                return null;
            }
            // try parse the string to a JSON object

        } // else promtError();
            // return JSON String
//      pd.dismiss();
        error();
        return null;

エラーログ:

07-03 11:37:22.465: W/System.err(1112): java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 11:37:22.476: W/System.err(1112):     at libcore.io.IoBridge.open(IoBridge.java:416)
07-03 11:37:22.476: W/System.err(1112):     at java.io.FileInputStream.<init>(FileInputStream.java:78)
07-03 11:37:22.476: W/System.err(1112):     at org.apache.http.entity.mime.content.FileBody.writeTo(FileBody.java:92)
07-03 11:37:22.476: W/System.err(1112):     at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:162)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestEntity(AbstractClientConnAdapter.java:272)
07-03 11:37:22.486: W/System.err(1112):     at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:119)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-03 11:37:22.495: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-03 11:37:22.505: W/System.err(1112):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.adapter.JSONParser.getJSONFromUrl(JSONParser.java:290)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.AddFillActivityApp$Upload.doInBackground(AddFillActivityApp.java:473)
07-03 11:37:22.505: W/System.err(1112):     at ua.mirkvartir.android.frontend.AddFillActivityApp$Upload.doInBackground(AddFillActivityApp.java:1)
07-03 11:37:22.505: W/System.err(1112):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-03 11:37:22.515: W/System.err(1112):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-03 11:37:22.515: W/System.err(1112):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-03 11:37:22.515: W/System.err(1112):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-03 11:37:22.546: W/System.err(1112):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-03 11:37:22.546: W/System.err(1112):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-03 11:37:22.556: W/System.err(1112):     at java.lang.Thread.run(Thread.java:856)
07-03 11:37:22.556: W/System.err(1112): Caused by: libcore.io.ErrnoException: open failed: EISDIR (Is a directory)
07-03 11:37:22.565: W/System.err(1112):     at libcore.io.IoBridge.open(IoBridge.java:405)
07-03 11:37:22.575: W/System.err(1112):     ... 24 more

この問題を解決する方法を教えてもらえますか?

4

0 に答える 0