使用JsonHttpResponseHandler()时如何修复404错误?

问题描述 投票:0回答:1

[尝试创建一个简单的电影放映时间移动应用程序。我之前在另一个类中使用过this方法,它可以正常工作,但是由于某种原因,在当前类中我收到404错误。

client.get(String.format(VIDEO_URL, 209112), new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Headers headers, JSON json) {
                        try {
                            JSONArray results = json.jsonObject.getJSONArray("results");
                            if(results.length() == 0){
                                return;
                            }
                            String youtubeKey = results.getJSONObject(0).getString("key");
                        } catch (JSONException e) {
                            Log.e("DetailActivity", "Failed to parse JSON", e);
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Headers headers, String response, Throwable throwable) {
                        System.out.println("On failure again " +statusCode  + " response: " + response);
                    }
                });

我的gradle文件中也有依赖项行。

implementation 'com.codepath.libraries:asynchttpclient:0.0.9'

这是我收到的onFailure消息

On failure again 404 response: {"status_code":34,"status_message":"The resource you requested could not be found."}
java android-studio
1个回答
0
投票

HTTP 404错误是服务器端错误。

404 not found

问题应该与您的android代码无关。您可以检查所请求的网址是否确实存在。

© www.soinside.com 2019 - 2024. All rights reserved.