Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.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 改进同步请求错误_Android - Fatal编程技术网

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";
}