java.lang中. RuntimeException找不到Retrofit批注. (参数3)

java.lang中. RuntimeException找不到Retrofit批注. (参数3),第1张

概述我正在尝试更新此RetroFit+Ottotutorial,所以我更新的代码是:IWeather.javaRetroFit2不允许返回空值,因此我将Call<Weather>添加为空getWeather(…),而不是空值.的GetWeather(…).publicinterfaceIWeather{@GET("/{latitude},{longitude}")Call<Weather>get

我正在尝试更新此RetroFit + Otto tutorial,所以我更新的代码是:

IWeather.java

RetroFit 2不允许返回空值,因此我将Call< Weather>添加为空getWeather(…),而不是空值.的GetWeather(…).

public interface IWeather {    @GET("/{latitude},{longitude}")    Call<Weather> getWeather(@Path("latitude") String latitude,                             @Path("longitude") String longitude,                             Callback<Weather> callback);} 

ForecastClIEnt.java

RetroFit 2.更改了其构造函数,因此新的ForecastClIEnt具有下一种形式. IllegalArgumentException指向weather.getWeather(…)方法.

public class ForecastClIEnt {    private static final String BASE_URL = "https://API.darksky.net/forecast/";    private static final String API_KEY = "******************";    public static final String API_URL = BASE_URL + API_KEY + "/";    private static ForecastClIEnt mForecastClIEnt;    private static Retrofit mRetroAdapter;    public static ForecastClIEnt getClIEnt() {        if (mForecastClIEnt == null) {            mForecastClIEnt = new ForecastClIEnt();        }        return mForecastClIEnt;    }    private ForecastClIEnt() {        mRetroAdapter = new Retrofit.Builder()                .baseUrl(API_URL)                .addConverterFactory(GsonConverterFactory.create())                .clIEnt(new OkhttpClIEnt())                .build();    }    public voID getWeather(String latitude, String longitude, Callback<Weather> callback) {        IWeather weather = mRetroAdapter.create(IWeather.class);        weather.getWeather(latitude, longitude, callback);    }}

ForecastManager.java

public class ForecastManager {    private Context mContext;    private Bus mBus;    private ForecastClIEnt sForecastClIEnt;    public ForecastManager(Context context, Bus bus) {        this.mContext = context;        this.mBus = bus;        sForecastClIEnt = ForecastClIEnt.getClIEnt();    }    @Subscribe    public voID onGetWeatherEvent(GetWeatherEvent getWeatherEvent) {        String latitude = Double.toString(getWeatherEvent.getLatitude()).trim();        String longitude = Double.toString(getWeatherEvent.getLongitude()).trim();        Callback<Weather> callback = new Callback<Weather>() {            @OverrIDe            public voID onResponse(Call<Weather> call, Response<Weather> response) {                Log.d(ForecastManager.class.getSimplename(), response.body().toString());                mBus.post(new SenDWeatherEvent(response.body()));            }            @OverrIDe            public voID onFailure(Call<Weather> call, Throwable t) {                Log.e(ForecastManager.class.getSimplename(), t.getMessage());            }        };        sForecastClIEnt.getWeather(latitude, longitude, callback);    }}

我收到未找到No Retrofit批注,并且原因可能与回调有关,但它是RetroFit回调,因此我不明白为什么会出错.

堆栈跟踪指向MainActivity,特别是指向具有java.lang.RuntimeException的otto方法post():无法分派事件,原因是先前提到的java.lang.IllegalArgumentException的错误:未找到Retrofit批注. (参数3):

MainActivity.java

public class MainActivity extends AppCompatActivity {    @BindVIEw(R.ID.activity_main_textVIEw)    TextVIEw textVIEw;    @BindVIEw(R.ID.activity_main_button)    button button;    private static final double LATITUDE = **.******;    private static final double LONGITUDE = **.******;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        ButterKnife.bind(this);    }    @OnClick(R.ID.activity_main_button)    public voID onClick(VIEw vIEw) {        BusProvIDer.getInstace().post(new GetWeatherEvent(LATITUDE, LONGITUDE));    }    @Subscribe    public voID onSenDWeatherEvent(SenDWeatherEvent senDWeatherEvent) {        Weather weather = senDWeatherEvent.getWeather();        Currently currently = weather.getCurrently();        textVIEw.setText(currently.getSummary());    }

关于错误在哪里的任何线索,或者我应该如何处理总线订阅,回调等?

解决方法:

java.lang.IllegalArgumentException:未找到Retrofit注释. (参数3)

如错误所述,问题是getWeather方法的第三个参数没有注释. Callback类用于Call#enqueue(Callback)方法.

只需将sForecastClIEnt.getWeather(纬度,经度,回调)更改为sForecastClIEnt.getWeather(纬度,经度).排队(回调)并删除第三个参数.

总结

以上是内存溢出为你收集整理的java.lang中. RuntimeException找不到Retrofit批注. (参数3)全部内容,希望文章能够帮你解决java.lang中. RuntimeException找不到Retrofit批注. (参数3)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094270.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存