【发布时间】:2020-02-27 15:50:12
【问题描述】:
我在 Android Studio 中使用 Retrofit 和 API,但不确定我哪里出错了。那是我的 API java 代码。我在值、编码的表单 url 和帖子上遇到错误
<package com.example.coffeeshopapp.Retrofit;
import com.example.coffeeshopapp.Model.User;
import com.example.coffeeshopapp.Model.checkUserResponse;
import retrofit2.http.FormUrlEncoded
public interface CoffeeShopAPI {
@FormUrlEncoded
@POST("checkuser.php")
Call<checkUserResponse> checkUserExists(@Field("phone")String phone);
@FormUrlEncoded
@POST("register.php")
Call<User> registerNewUser(@Field("phone")String phone,
@Field("name")String name,
@Field("address")String address,
@Field("birthdate")String birthdate);
}
这是我的改造代码。改造和 gson 转换器工厂的错误。
package com.example.coffeeshopapp.Retrofit;
import Retrofit;
public class RetrofitClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl)
{
if (retrofit == null)
{
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
【问题讨论】:
-
请分享你的错误日志。
-
改造错误:无法解析符号改造和gson转换器工厂
-
api 错误:无法解析符号:post、formurlencoded、call 和 field
-
好像你没有导入必要的包确保你已经导入它们你可以按 Alt+Enter 快捷键并导入必要的包
-
用于改造、表单 url 编码、发布和调用的包不显示我是否打算将它们添加到 gradle 文件中的依赖项中?
标签: android rest gson retrofit