【发布时间】:2013-06-25 21:35:39
【问题描述】:
我正在开发一个使用 Apache Commons IO、commons-io-2.4-bin.tar.gz 的 Android 应用程序。
我得到了一些错误,其中之一:
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());
【问题讨论】:
标签: java android apache-commons