Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 改型2 onResponse方法未调用,尽管Http请求返回数据_Android_Retrofit2 - Fatal编程技术网

Android 改型2 onResponse方法未调用,尽管Http请求返回数据

Android 改型2 onResponse方法未调用,尽管Http请求返回数据,android,retrofit2,Android,Retrofit2,我正在发出一个异步http请求,调用一个web服务,它返回一个JSON格式的游戏日期列表。我可以在日志中看到正在返回数据,但是没有调用onResponse或onFailure方法 下面是我的代码片段,后面是显示http请求结果的日志。请注意,正在调用的web服务只被要求从Games表中返回30列中的1列(gameDate)。表中有两行,gameDate列从两行返回,如日志中所示。我正试图将游戏日期列表传回我的主要活动以供显示 有人知道为什么没有达到onResponse或onFailure方法吗

我正在发出一个异步http请求,调用一个web服务,它返回一个JSON格式的游戏日期列表。我可以在日志中看到正在返回数据,但是没有调用
onResponse
onFailure
方法

下面是我的代码片段,后面是显示http请求结果的日志。请注意,正在调用的web服务只被要求从
Games
表中返回30列中的1列(
gameDate
)。表中有两行,
gameDate
列从两行返回,如日志中所示。我正试图将游戏日期列表传回我的主要活动以供显示

有人知道为什么没有达到
onResponse
onFailure
方法吗

public interface GamesAPI {

    @GET("/HCDBWebService/HCDBWebService.php?format=json&operation=gameList")
    Call<List<Game>> listGames();

}




private void requestData() {

    Log.d("MainActivity.LOGTAG", "requestData method");

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(API_BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    GamesAPI api = retrofit.create(GamesAPI.class);

    Call<List<Game>> call = api.listGames();

    call.enqueue(new Callback<List<Game>>() {
        @Override
        public void onResponse(Call<List<Game>> call, Response<List<Game>> response) {
            if(response.isSuccessful()) {
                gameList = response.body();
            } else {
                Log.e("Error code", String.valueOf(response.code()));
                Log.e("Error body", response.errorBody().toString());
            }
        }

        @Override
        public void onFailure(Call<List<Game>> call, Throwable t) {
            Log.d("Error", t.getMessage());
        }
    });
}
公共接口GamesAPI{
@GET(“/HCDBWebService/HCDBWebService.php?format=json&operation=gameList”)
调用listGames();
}
私有void requestData(){
Log.d(“MainActivity.LOGTAG”,“requestData方法”);
HttpLoggingInterceptor拦截器=新的HttpLoggingInterceptor();
拦截器.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient客户端=新建OkHttpClient.Builder().addInterceptor(拦截器).build();
改装改装=新改装.Builder()
.baseUrl(API_BASE_URL)
.客户(客户)
.addConverterFactory(GsonConverterFactory.create())
.build();
GamesAPI api=改装.create(GamesAPI.class);
Call Call=api.listGames();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
gameList=response.body();
}否则{
Log.e(“错误代码”,String.valueOf(response.code());
Log.e(“错误体”,response.errorBody().toString());
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.d(“Error”,t.getMessage());
}
});
}
日志输出:

 D/OkHttp: Date: Thu, 22 Sep 2016 13:42:54 GMT
 D/OkHttp: Server: Apache/2.2.31 (Unix) mod_wsgi/3.5 Python/2.7.12 PHP/7.0.10 mod_ssl/2.2.31 OpenSSL/1.0.2h DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0
 D/OkHttp: X-Powered-By: PHP/7.0.10
 D/OkHttp: Content-Length: 53
 D/OkHttp: Keep-Alive: timeout=5, max=100
 D/OkHttp: Connection: Keep-Alive
 D/OkHttp: Content-Type: application/json
 D/OkHttp: [{"gameDate":"2016-09-15"},{"gameDate":"2016-09-19"}]
 D/OkHttp: <-- END HTTP (53-byte body)
D/OkHttp:Date:Thu,2016年9月22日13:42:54格林威治标准时间
D/OkHttp:Server:Apache/2.2.31(Unix)mod_wsgi/3.5 Python/2.7.12 PHP/7.0.10 mod_ssl/2.2.31 OpenSSL/1.0.2h DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 perl/v5.24.0
D/OkHttp:X-Powered-By:PHP/7.0.10
D/OkHttp:内容长度:53
D/OkHttp:Keep-Alive:timeout=5,max=100
D/OkHttp:连接:保持活动状态
D/OkHttp:Content-Type:application/json
D/OkHttp:[{“游戏日期”:“2016-09-15”},{“游戏日期”:“2016-09-19”}]

也许已经太晚了,但我试着回答你的问题。您对列表的问题。只需将所有使用它们的
**列表**
更改为
**游戏**
。这应该会有帮助

示例:

Call Call=api.listGames();

Call Call=api.listGames();

也许已经太晚了,但我试着回答你的问题。您对列表的问题。只需将所有使用它们的
**列表**
更改为
**游戏**
。这应该会有帮助

示例:

Call Call=api.listGames();

Call Call=api.listGames();

请至少添加一个问题我的问题已嵌入到我的文本中。我只是编辑并附加到我的文本末尾(有人知道为什么onResponse和onFailure方法都没有被访问吗?)没有什么是不正确的。这听起来可能很愚蠢,但是如果
response.issusccessful()
,您是否尝试过记录一些内容?您正在设置
gameList=response.body()
,但在设置值之后,您可能从未真正使用过
gameList
?这是个好问题,布莱恩。我没有尝试记录if response.issusccessful(),所以我只是插入了一个日志并重新运行。同样的事情正在发生。当我在调试模式下单步执行时,光标从call.enqueue行直接移动到call.enqueue方法的右括号。为了回答您的另一个问题,gameList实际上是在调用my getRequest()方法之后被引用的。我将在这里向您展示代码:requestData();GameAdapter GameAdapter=新GameAdapter(此,R.layout.game\u列表项,gameList);list.setAdapter(gameAdapter);尝试更新游戏适配器列表gameList.addAll(response.body())尝试登录onResponse方法以确保我们在那里请至少添加一个问题我的问题已嵌入到我的文本中。我只是编辑并附加到我的文本末尾(有人知道为什么onResponse和onFailure方法都没有被访问吗?)没有什么是不正确的。这听起来可能很愚蠢,但是如果
response.issusccessful()
,您是否尝试过记录一些内容?您正在设置
gameList=response.body()
,但在设置值之后,您可能从未真正使用过
gameList
?这是个好问题,布莱恩。我没有尝试记录if response.issusccessful(),所以我只是插入了一个日志并重新运行。同样的事情正在发生。当我在调试模式下单步执行时,光标从call.enqueue行直接移动到call.enqueue方法的右括号。为了回答您的另一个问题,gameList实际上是在调用my getRequest()方法之后被引用的。我将在这里向您展示代码:requestData();GameAdapter GameAdapter=新GameAdapter(此,R.layout.game\u列表项,gameList);list.setAdapter(gameAdapter);尝试更新de-Game适配器列表,gameList.addAll(response.body())尝试登录onResponse方法以确保我们在那里
Call<List<Game>> call = api.listGames();
Call<Game> call = api.listGames();