我试图用Retrofit做一个简单的REST请求,并且我得到了很多GC错误。我真的不知道如何解决它。我试图在模拟器上添加更多内存,但问题仍然存在。何时进行同步通话Response<List<User>> response = usersCall.execute();
以下异常
java.lang.RuntimeException: An error occurred while executing doInBackground()
android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Cause by: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:831)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:422)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:410)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
并使用pojo模型Response<List<User>> response = usersCall.execute();
然后
04-09 07:37:23.897 13396-13411/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:23.897 13396-13411/? I/art: Background partial concurrent mark sweep GC freed 3104(48KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 7.520ms total 194.127ms
04-09 07:37:23.897 13396-13396/? I/art: WaitForGcToComplete blocked for 182.909ms for cause Alloc
04-09 07:37:23.929 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 128(5KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 8.237ms total 31.761ms
04-09 07:37:23.929 13396-13396/? I/art: WaitForGcToComplete blocked for 18.171ms for cause Alloc
04-09 07:37:24.130 13396-13411/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.130 13396-13411/? I/art: Background partial concurrent mark sweep GC freed 5784(90KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 9.388ms total 200.412ms
04-09 07:37:24.130 13396-13396/? I/art: WaitForGcToComplete blocked for 200.758ms for cause Alloc
04-09 07:37:24.158 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 1710(34KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.897ms total 27.286ms
04-09 07:37:24.158 13396-13396/? I/art: WaitForGcToComplete blocked for 18.297ms for cause Alloc
04-09 07:37:24.346 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.346 13396-13396/? I/art: Alloc partial concurrent mark sweep GC freed 2092(33KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 5.943ms total 188.191ms
04-09 07:37:24.370 13396-13396/? I/art: Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 8.501ms total 23.440ms
04-09 07:37:24.566 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.566 13396-13396/? I/art: Alloc concurrent mark sweep GC freed 9(12KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.105ms total 195.296ms
04-09 07:37:24.566 13396-13411/? I/art: WaitForGcToComplete blocked for 395.241ms for cause Background
04-09 07:37:24.598 13396-13411/? I/art: Background sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 6.138ms total 29.195ms
04-09 07:37:24.598 13396-13396/? I/art: WaitForGcToComplete blocked for 29.063ms for cause Alloc
04-09 07:37:24.775 13396-13396/? I/art: Clamp target GC heap from 111MB to 96MB
04-09 07:37:24.775 13396-13396/? I/art: Alloc partial concurrent mark sweep GC freed 16(56KB) AllocSpace objects, 1(54KB) LOS objects, 0% free, 95MB/96MB, paused 6.803ms total 177.429ms
我的代码:
Gson gson =
new GsonBuilder()
.registerTypeAdapter(Usuario.class, new UsuarioDeserializer())
.registerTypeAdapter(Date.class, new CustomDateDeserializer())
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ConstantesUtil.URL_BASE)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
UsuariosAPI usuarioApi = retrofit.create(UsuariosAPI.class);
Usuario usuario = new Usuario(login, senha);
Call<List<Usuario>> usuarios = usuarioApi.getUsuarios(usuario);
usuarios.enqueue(new Callback<List<Usuario>>() {
@Override
public void onResponse(Call<List<Usuario>> call, Response<List<Usuario>> response) {
List<Usuario> usuarios = response.body();
for (Usuario u: usuarios) {
Log.i(TAG, u.getNome());
}
}
@Override
public void onFailure(Call<List<Usuario>> call, Throwable t) {
}
});
答案 0 :(得分:3)
我意识到这个问题(infinate GC循环)发生在模型(&#34; Usuario&#34;在你的情况下)有一个成员变量导致序列化问题。
<input type="text" placeholder="search" ng-model="objectsearch">
<div ng-repeat="x in inputobject | filter:{name:objectsearch}">
<div>
{{x.name}} {{x.lastname}}
</div>
</div>
答案 1 :(得分:0)
从pojo类中删除任何字节数组和Drawable,或使其成为瞬态。 享受