2015-12-13 43 views
0

我在嘗試更新到com.loopj.android:android-async-http的最新版本(1.4.9),其中org.apache.http已被cz.msebera.android.httpclient替換。創建HttpEntity

目前我使用:

StringEntity entity = new StringEntity("some data"); 
client.post(static_context, getAbsoluteUrl(url), entity, "application/json", responseHandler); 

所以我想我可以將它轉換爲HttpEntity這是情況並非如此。

Caused by: java.lang.ClassCastException: org.apache.http.entity.StringEntity cannot be cast to cz.msebera.android.httpclient.HttpEntity 

所以我的問題是我如何可以創建我的數據HttpEntity或是否有更好的方法來創建主體數據POST請求?

回答

2

它看起來像你導入了錯誤StringEntity類。

假設cz.msebera.android.httpclient仍具有StringEntity,你應該能的

import cz.msebera.android.httpclient.entity.StringEntity 

代替

import org.apache.http.entity.StringEntity 
+0

嗯,我認爲到,但它並非如此。 –

+0

嗯..在某個時候使用'org.apache.http。*'類,否則你不會得到這個ClassCastException。 – Floern

+0

啊,你是對的,StringEntity是'org.apache.http.entity.StringEntity',但我沒有在'cz.msebera.android.httpclient.'找到類似的類。' –

相關問題