Android 改进同步请求错误
我正在为呼叫改造同步请求编写以下代码:Android 改进同步请求错误,android,Android,我正在为呼叫改造同步请求编写以下代码: public String LOGININTO() throws IOException { final String[] message = {""}; LOGININTERFACE taskService = ServiceGenerator.createService(LOGININTERFACE.class); Call<LGOINMODEL> tasks = taskService.savePost("0
public String LOGININTO() throws IOException {
final String[] message = {""};
LOGININTERFACE taskService = ServiceGenerator.createService(LOGININTERFACE.class);
Call<LGOINMODEL> tasks = taskService.savePost("0016642902","0016642902","password");
LGOINMODEL model=null;
model=tasks.execute().body();
return "OK";
}
公共字符串LOGININTO()引发IOException{
最后一个字符串[]消息={”“};
LOGININTERFACE taskService=ServiceGenerator.createService(LOGININTERFACE.class);
调用tasks=taskService.savePost(“0016642902”、“0016642902”、“密码”);
LGOINMODEL model=null;
model=tasks.execute().body();
返回“OK”;
}
但是当运行我的代码时会出现以下错误:
在
原因:android.os.NetworkOnMainThreadException
改装2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
我怎样才能解决这个问题
谢谢。将您的执行包装在
新线程()上。
:
公共字符串LOGININTO()引发IOException{
最后一个字符串[]消息={”“};
LOGININTERFACE taskService=ServiceGenerator.createService(LOGININTERFACE.class);
调用tasks=taskService.savePost(“0016642902”、“0016642902”、“密码”);
LGOINMODEL model=null;
Thread Thread=新线程(new Runnable(){
@凌驾
公开募捐{
model=tasks.execute().body();
}
});
thread.start();
返回“OK”;
}
请详细说明您到底遇到了什么错误请尝试此操作
public String LOGININTO() throws IOException {
final String[] message = {""};
LOGININTERFACE taskService = ServiceGenerator.createService(LOGININTERFACE.class);
Call<LGOINMODEL> tasks = taskService.savePost("0016642902","0016642902","password");
LGOINMODEL model=null;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
model=tasks.execute().body();
}
});
thread.start();
return "OK";
}