我正在开发一个 Android 应用程序,使用Apache 公共 IO http://commons.apache.org/proper/commons-io/download_io.cgi, commons-io-2.4-bin.tar.gz.
我收到一些错误,其中之一:
Could not find method java.lang.String.getBytes, referenced from method org.apache.commons.io.IOUtils.toInputStream
我想我不用担心这个,不是吗?
我可以使用另一个特定的 Android 库来代替 Apache Commons IO 吗?
我在这里使用它:
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
import android.util.Log;
public class CustomResponseErrorHandler implements ResponseErrorHandler
{
private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
@Override
public void handleError(ClientHttpResponse response) throws IOException
{
String theString = IOUtils.toString(response.getBody());
Log.v("Error Handler", theString);
CustomException exception = new CustomException();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("code", response.getStatusCode().toString());
properties.put("body", theString);
properties.put("header", response.getHeaders());
exception.setProperties(properties);
throw exception;
}
@Override
public boolean hasError(ClientHttpResponse response) throws IOException
{
return errorHandler.hasError(response);
}
}
在这一行:
String theString = IOUtils.toString(response.getBody());
我建议使用 Apache Commons IO 库源,然后将其打包到 Android :) 我已将其打包在存储库中here https://github.com/smannlymann/ApacheCommonsIO-for-Android。只需将其导入您选择的 IDE 即可!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)