前提・実現したいこと
retrofitを使って天気情報を取得したい
発生している問題・エラーメッセージ
参考サイト
上記サイトを参考に、プログラムを書き進めていたのですが、
WeatherApi api = adapter.create(WeatherApi.interface);
という1文において、"identifierがありません"と";"がありません。というエラーが出ています。
また
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
というエラーも出ています。
どなたか解決法を教えてください…。
該当のソースコード
Java
1package com.example.ren.helloandroid; 2 3import android.support.v7.app.AppCompatActivity; 4import android.os.Bundle; 5 6import retrofit2.Response; 7import retrofit2.Retrofit; 8 9public class MainActivity extends AppCompatActivity { 10 11 private static final String API = "http://api.openweathermap.org/data/2.5"; 12 private static final float LAT = 35.681382f; 13 private static final float LON = 139.766084f; 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.activity_main); 19 20 //デフォルトのアダプター(converter)はjson用 21 //json以外の形式をサポートするには別途converterの実装が必要 22 Retrofit adapter = new Retrofit().Builder() 23 .setEndpoint(API) 24 .build(); 25 WeatherApi api = adapter.create(WeatherApi.interface); 26 api.getWeather(LAT, LON, new Callback<WeatherData>() { 27 @Override 28 public void success(WeatherData weatherData, Response response) { 29 for (Weather w : weatherData.getWeather()) { 30 System.out.println("Weather Description : " + w.getDescription()); 31 } 32 } 33 34 @Override 35 public void failure(RetrofitError error) { 36 37 } 38 }); 39 } 40} 41
Java
1import retrofit2.Callback; 2import retrofit2.http.GET; 3import retrofit2.http.Query; 4 5public interface WeatherApi { 6 @GET("/weather") 7 public void getWeather(@Query("lat") float lat, @Query("lon") float lon, Callback<WeatherData> response); 8} 9 10
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/02/21 02:05