2017-01-04 1 views
0

のNoClassDefFoundErrorのURIファイルパスを使用してFileBodyを作成中に致命的な例外が発生しました。MultipartEntityBuilderの致命的な例外を取得する

try { 
     HttpClient httpClient = new DefaultHttpClient(); 
     HttpContext httpContext = new BasicHttpContext(); 
     HttpPost httpPost = new HttpPost(URLIMG); 
     try{ 

      MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create(); 
      multipartEntity.addPart("userfile", new FileBody(new File(file.getPath()))); 
      // Send it 
      httpPost.setEntity(multipartEntity.build()); 
      Log.e("post" , httpPost.toString()); 
      HttpResponse response = httpClient.execute(httpPost, httpContext); 
      String serverResponse = EntityUtils.toString(response.getEntity()); 
      Log.e("sd","serverResponse = "+serverResponse); 
     }catch (Exception e) 
     { 
      Log.e("Exception", "Exception: " + e.toString()); 
     } 
    }catch (Exception e) 
    { 
     Log.e("Exception", "Exception: " + e.toString()); 
     e.printStackTrace(); 
    } 

と私のログは次のとおりです。ContentType.javaとして

01-04 18:15:13.881 15372-15372/com.example.hp_pc.cerv E/AndroidRuntime: FATAL EXCEPTION: main 
                    Process: com.example.hp_pc.cerv, PID: 15372 
                    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/entity/ContentType; 
                     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:89) 
+0

は が は「META-INFを除外する 'META-INF/NOTICE' を排除し、私はこの packagingOptions { は 'META-INF/ASL2.0' を除外 は 'META-INF/LICENSE' を除外を持ってあなたのbuild.gradle –

+0

を表示します/ DEPENDENCIES」 } とファイルをコンパイル( 'LIBS/HTTPClientの-4.2.3.jar') ファイルをコンパイル( 'LIBS/httpmime-4.3.jarを') ファイルをコンパイル( 'LIBS/httpcore.jar') –

+0

1つのバージョンのすべてのライブラリを持ってみてください、それは問題になる可能性があります –

答えて

0

V4.2以降httpcoreで利用可能です。 httpcoreのバージョンが間違っている可能性が高いです。

この問題を解決するには、正しいバージョンのhttpcoreをアーティファクトリポジトリで検索してください。この場合、4.2.2download itとなり、現在のバージョンと交換してください。

あなたのビルドシステムについて知らずに、httpcore.jarを出荷していないこともあります。この場合、他の2つのジャーと同じ仕組みを使用してください。

現代のビルドシステムの依存関係管理機能を使用する場合は、おそらくGradleか、少なくともjarファイルのバージョン番号を保持してください。

関連する問題