我是使用这个android库的新手,下面的代码是我简单的inslemented Retrofit库,运行项目后我没有得到任何错误,但我的项目挂断并且无法正常工作。
使用后的详细logcat消息Retrofit Call函数:
06-04 03:10:44.647 21694-21709/ir.pishguy.signalpresentationproject I/art: Background sticky concurrent mark sweep GC freed 196320(5MB) AllocSpace objects, 36(1935KB) LOS objects, 5% free, 85MB/90MB, paused 7.388ms total 52.997ms
06-04 03:10:44.802 21694-21704/ir.pishguy.signalpresentationproject W/art: Suspending all threads took: 26.926ms
06-04 03:10:44.844 21694-21709/ir.pishguy.signalpresentationproject I/art: Background sticky concurrent mark sweep GC freed 135992(3MB) AllocSpace objects, 31(1674KB) LOS objects, 5% free, 85MB/90MB, paused 6.324ms total 49.940ms
06-04 03:10:45.185 21694-21709/ir.pishguy.signalpresentationproject I/art: Clamp target GC heap from 101MB to 96MB
06-04 03:10:45.185 21694-21709/ir.pishguy.signalpresentationproject I/art: Background partial concurrent mark sweep GC freed 246201(7MB) AllocSpace objects, 59(3MB) LOS objects, 10% free, 85MB/96MB, paused 6.412ms total 212.381ms
06-04 03:10:45.185 21694-21694/ir.pishguy.signalpresentationproject I/art: WaitForGcToComplete blocked for 119.899ms for cause Alloc
06-04 03:10:45.476 21694-21709/ir.pishguy.signalpresentationproject I/art: Background sticky concurrent mark sweep GC freed 240528(6MB) AllocSpace objects, 48(2MB) LOS objects, 8% free, 86MB/94MB, paused 7.318ms total 54.547ms
06-04 03:10:45.476 21694-21694/ir.pishguy.signalpresentationproject I/art: WaitForGcToComplete blocked for 35.245ms for cause Alloc
06-04 03:10:51.268 21694-21702/ir.pishguy.signalpresentationproject I/art: Thread[5,tid=21702,WaitingInMainSignalCatcherLoop,Thread*=0xef60d400,peer=0x12c00080,"Signal Catcher"]: reacting to signal 3
06-04 03:10:51.603 21694-21702/ir.pishguy.signalpresentationproject I/art: Wrote stack traces to '/data/anr/traces.txt'
我的代码:
SignalProvider
上课:
public class SignalProvider {
private SignalServices signalServices;
public SignalProvider(){
OkHttpClient httpClient = new OkHttpClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ClientSettings.SignalWebBaseUrl)
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
signalServices = retrofit.create(SignalServices.class);
}
public SignalServices getServices(){
return signalServices;
}
}
SignalServices
接口类:
public interface SignalServices {
@GET("storeLists")
Call<List<Store>> getStoreLists();
}
ClientSettings
上课:
public class ClientSettings {
public static final String SignalWebBaseUrl = "http://192.168.1.35/signal/public/";
}
然后我通过这种方法从活动中使用它们:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
SignalProvider signalProvider = new SignalProvider();
SignalServices signalServices = signalProvider.getServices();
Store store = new Store();
Call<List<Store>> call = signalServices.getStoreLists();
call.enqueue(new Callback<List<Store>>() {
@Override
public void onResponse(Call<List<Store>> call, Response<List<Store>> response) {
}
@Override
public void onFailure(Call<List<Store>> call, Throwable t) {
}
});
}
运行项目后一段时间我的应用程序崩溃
答案 0 :(得分:2)
解决了问题
在一些调试应用程序之后,我在Gradle上将targetSdkVersion
从23
更改为22
,然后问题解决了