代码运行正常,但是在我添加行以在Apollo客户端类中实现缓存后,出现此错误,应用无法编译。
当我删除缓存行时,它开始编译并正常工作。我认为我没有正确设置缓存。
我试图使缓存无效并重新启动,并删除生成的文件,以为可以通过重新创建类来解决问题,但是问题仍然存在。
这是客户:
public class MyApolloClient {
private static final String BASE_URL = "http://192.168.43.33:4444/";
private static ApolloClient apolloClient = null;
public static ApolloClient getApolloClient(Context context) {
if (apolloClient != null) {
return apolloClient;
} else {
//Directory where cached responses will be stored
File file = new File(context.getApplicationContext().getCacheDir().toString());
//Size in bytes of the cache
int size = 1024 * 1024;
//Create the http response cache store
DiskLruHttpCacheStore cacheStore = new DiskLruHttpCacheStore(file, size);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
apolloClient = ApolloClient.builder().serverUrl(BASE_URL).httpCache(new ApolloHttpCache(cacheStore)).okHttpClient(okHttpClient).build();
return apolloClient;
}
}
}
而且,这是唯一使用它的时间:
MyApolloClient.getApolloClient(this).mutate(
LoginMutation.builder().email(emailEditText.text.toString())
.password(passwordEditText.text.toString())
.build()
).enqueue(object : ApolloCall.Callback<LoginMutation.Data>() {
override fun onResponse(response: Response<LoginMutation.Data>) {
/*val intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)*/
Log.e("success",response.data().toString())
}
override fun onFailure(e: ApolloException) {
Log.e("failed", e.toString())
}
})
谢谢。