2015-11-04 99 views
1

我的錯誤:誤差照片上傳到服務器的Android

java.lang.NoSuchFieldError的:org.apache.http.message.BasicHeaderValueFormatter.INSTANCE

我的代碼:

public static String POST(String path, JSONObject params, String fileName) 
      throws ClientProtocolException, IOException { 
     HttpPost request = new HttpPost(url + path); 

     MultipartEntity multipartEntity = new MultipartEntity(); 

     FileBody bin = new FileBody(new File(fileName), "image/jpeg"); 
     multipartEntity.addPart("photo", bin); 
     for (Object obj : params.entrySet()) { 
      Entry e = (Entry)obj; 
      multipartEntity.addPart((String)e.getKey(), new StringBody((String)e.getValue())); 
     } 
     request.setEntity(multipartEntity); 
     HttpResponse response = httpClient.execute(request); 

     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
     String result = ""; 
     String line = ""; 
     while ((line = bufferedReader.readLine()) != null) 
      result += line; 
     bufferedReader.close(); 
     return result; 
    } 

的gradle我:

packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    compile 'com.andreabaccega:android-form-edittext:[email protected]' 
    compile files('libs/gson-2.2.1.jar') 
    compile files('libs/json-simple-1.1.1.jar') 
    compile files('libs/httpmime-4.5.1.jar') 
    compile files('libs/httpcore-4.4.3.jar') 
    compile files('libs/httpclient-4.5.1.jar') 
    compile files('libs/commons-lang3-3.1.jar') 
    compile files('libs/commons-logging-1.1.2.jar') 
} 

我想使用HTTP POST將文件(特定圖像)上載到服務器。 如何解決這個問題?

+0

http://stackoverflow.com/a/32702347/2533290 ,可以幫助。或者其他解決方案:更新你的gradle到1.4.0-beta6(更新的版本可以在這裏找到:https://jcenter.bintray.com/com/android/tools/build/gradle/) 並且說useLibrary'org.apache .http.legacy'在Android範圍 希望它有幫助。 –

+0

什麼是垃圾箱? – Prakhar

回答

0

我想你會需要使用android port version of http client from apache
試圖改變自己的gradle這個依賴於這樣的:

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    compile 'com.andreabaccega:android-form-edittext:[email protected]' 
    compile files('libs/gson-2.2.1.jar') 
    compile files('libs/json-simple-1.1.1.jar') 
    compile('org.apache.httpcomponents:httpmime:4.5.1') { 
     exclude module: 'httpclient' 
    } 
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 
    compile files('libs/httpcore-4.4.3.jar') 
    compile files('libs/commons-lang3-3.1.jar') 
    compile files('libs/commons-logging-1.1.2.jar') 
} 
+0

錯誤:(36,0)未找到Gradle DSL方法:'exclude()' – user3712384

+0

錯誤:(35,0)未找到Gradle DSL方法:'compile()' – user3712384

+0

錯誤:執行任務失敗:app:dexDebug 」。 > com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:進程'命令'C:\ Program Files \ Java \ jdk1.8.0_31 \ bin \ java.exe''已完成非零退出值2 – user3712384

相關問題