我目前正在使用Android工作室。我在编译文件时遇到问题。我一直在收到这个错误。我搜索了类似的问题,但它没有帮助我。
private void queryBooks(String searchString){
// Prepare your search string to be put in a URL
// It might have reserved characters or something
String urlString = "";
try {
urlString = URLEncoder.encode(searchString, "UTF-8");
} catch (UnsupportedEncodingException e) {
// if this fails for some reason, let the user know why
e.printStackTrace();
Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
// Create a client to perform networking
AsyncHttpClient client = new AsyncHttpClient();
// Have the client get a JSONArray of data
// and define how to respond
client.get(QUERY_URL + urlString,
new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONObject jsonObject) {
// Display a "Toast" message
// to announce your success
Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
// 8. For now, just log results
Log.d("omg android", jsonObject.toString());
}
@Override
public void onFailure(int statusCode, Throwable throwable, JSONObject error) {
// Display a "Toast" message
// to announce the failure
Toast.makeText(getApplicationContext(), "Error: " + statusCode + " " + throwable.getMessage(), Toast.LENGTH_LONG).show();
// Log error message
// to help solve any problems
Log.e("omg android", statusCode + " " + throwable.getMessage());
}
}
答案 0 :(得分:0)
调试我的程序后。我找到了答案。我失踪了});在关闭我的程序之前。谢谢大家的帮助。