我正在尝试使用改造和json转换器使用Restful API发布用户名凭据,但遇到了问题。我的程序运行正常,无法建立连接。调用on failure函数,并发送Toast消息 套接字故障:EPERM(不允许操作)
我在清单文件中使用了这些权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
这就是我处理回复电话的方式
Call<ResponseBody> call= RetrofitClient
.getInstance()
.getApi()
.createUser(first_name,last_name,username,email,password,phoneNo);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
String s=response.body().toString();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(MainActivity.this,t.getMessage(),Toast.LENGTH_LONG).show();
}
});
我通过onfailure()方法得到错误
这是我创建的retrofitclient类
package com.example.usersignup_usingapi;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static final String BASE_URL="https://kamwene.000webhostapp.com/tza/tza/api/";
private static RetrofitClient mInstance;
private Retrofit retrofit;
private RetrofitClient(){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static synchronized RetrofitClient getInstance(){
if(mInstance == null){
mInstance = new RetrofitClient();
}
return mInstance;
}
public Api getApi(){
return retrofit.create(Api.class);
}
}
答案 0 :(得分:0)
尝试从设备/仿真器中卸载应用程序,然后重新运行它。