質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

2回答

718閲覧

【Android Studio】KotlinでのOpenWeatherAPIを用いた簡易天気情報取得アプリの開発(非同期処理とWebAPI連携)

kynsk

総合スコア2

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2023/10/12 08:50

編集2023/10/12 09:01

実現したいこと

  • openweatherのAPIを用いて簡易天気情報アプリを作成する

発生している問題・エラーメッセージ

デバッグをして、一行ごとに実行しているがとある一行を実行するとアプリケーションがエラー落ちをしてしまう問題がある。 ソースコード100行目にある↓のコードを実行すると落ちてしまう //レスポンスデータであるInputStreamオブジェクトを文字列に変換 result = is2String(stream) ネットワーク接続が問題と考えております。 どなたかご相談させてください。 また以下のインポートされたクラスは使われていません import java.net.Socket

該当のソースコード

MainActivity.kt

1package com.example.asyncsample 2 3import androidx.appcompat.app.AppCompatActivity 4import android.os.Bundle 5import android.util.Log 6import android.view.View 7import android.widget.AdapterView 8import android.widget.ListView 9import android.widget.SimpleAdapter 10import android.widget.TextView 11import androidx.annotation.UiThread 12import androidx.annotation.WorkerThread 13import org.json.JSONObject 14import java.io.BufferedReader 15import java.io.InputStream 16import java.io.InputStreamReader 17import java.lang.StringBuilder 18import java.net.HttpURLConnection 19import java.net.Socket 20import java.net.SocketTimeoutException 21import java.net.URL 22import java.nio.charset.StandardCharsets 23import java.util.concurrent.Callable 24import java.util.concurrent.Executors 25 26class MainActivity : AppCompatActivity() { 27 //クラス内のprivate定数を宣言するためにcompanion objectブロックとする 28 companion object{ 29 //ログに記載するタグ用の文字列 30 private const val DEBUG_TAG = "AsyncSample" 31 //お天気情報のURL 32 private const val WEATHERINFO_URL = "https://openweathermap.org/data/2.5/weather?lang=ja" 33 //お天気APIにアクセスするためのAPIキー 34 private const val APP_ID = "c1a8424a8556a2fa057cffa058930173" 35 } 36 //お天気情報の取得処理を行うメソッド 37 @UiThread 38 private fun receiveWeatherInfo(urlFull: String){ 39 val backgroundReceiver = WeatherInfoBackgroundReceiver(urlFull) 40 val executeService = Executors.newSingleThreadExecutor() 41 val future = executeService.submit(backgroundReceiver) 42 val result = future.get() 43 showWeatherInfo(result) 44 } 45 @UiThread 46 private fun showWeatherInfo(result: String){ 47 //ルートJSONオブジェクトを生成 48 val rootJSON = JSONObject(result) 49 //都市名文字列を取得 50 val cityName = rootJSON.getString("name") 51 //緯度経度情報JSONオブジェクトを取得 52 val coordJSON = rootJSON.getJSONObject("coord") 53 //緯度文字列を取得 54 val latitude = coordJSON.getString("lat") 55 //経度文字列を取得 56 val longitude = coordJSON.getString("lon") 57 //天気情報JSON配列オブジェクトを取得 58 val weatherJSONArray = rootJSON.getJSONArray("weather") 59 //現在の天気情報JSONオブジェクトを取得 60 val weatherJSON = weatherJSONArray.getJSONObject(0) 61 //現在の天気情報文字列を取得 62 val weather = weatherJSON.getString("description") 63 //画面に表示する「〇〇の天気」文字列を形成 64 val telop = "${cityName}の天気" 65 //天気の詳細情報を表示するTextViewを取得 66 val desc = "現在は${weather}です。\n緯度は${latitude}度で経度は${longitude}度です。" 67 //天気情報を表示するTextViewを取得 68 val tvWeatherTelop = findViewById<TextView>(R.id.tvWeatherTelop) 69 val tvWeatherDesc= findViewById<TextView>(R.id.tvWeatherDesc) 70 //天気情報を表示 71 tvWeatherTelop.text = telop 72 tvWeatherDesc.text = desc 73 } 74 //非同期でお天気情報APIにアクセスするためのクラス 75 private inner class WeatherInfoBackgroundReceiver(url:String): Callable<String> { 76 //お天気情報を取得するURL 77 private val _url = url 78 79 @WorkerThread 80 override fun call(): String { 81 var result = "" 82 83 //ここにWebAPIにアクセスするコードを記述 84 //URLオブジェクトを生成 85 val url = URL(_url) 86 //URLオブジェクトからHttpURLConnectionオブジェクトを取得 87 val con = url.openConnection() as HttpURLConnection 88 //接続に使ってもよい時間を設定 89 con.connectTimeout = 1000 90 //データ取得に使ってもよい時間 91 con.readTimeout = 1000 92 //HTTP接続メソッドをGETに設定 93 con.requestMethod = "GET" 94 try{ 95 //接続 96 con.connect() 97 //HttpURLConnectionオブジェクトからレスポンスデータを取得 98 val stream = con.inputStream//実行時に落ちる 99 //レスポンスデータであるInputStreamオブジェクトを文字列に変換 100 result = is2String(stream) 101 //InputStreamオブジェクトを解放 102 stream.close() 103 } 104 catch (ex: SocketTimeoutException){ 105 Log.w(DEBUG_TAG,"通信タイムアウト",ex) 106 } 107 con.disconnect() 108 return result 109 } 110 111 private fun is2String(stream: InputStream): String{ 112 val sb = StringBuilder() 113 val reader = BufferedReader(InputStreamReader(stream, StandardCharsets.UTF_8)) 114 var line = reader.readLine() 115 while(line != null) 116 { 117 sb.append(line) 118 line = reader.readLine() 119 } 120 reader.close() 121 return sb.toString() 122 } 123 } 124 //リストビューに表示させるリストデータ 125 private var _list: MutableList<MutableMap<String,String>> = mutableListOf() 126 127 override fun onCreate(savedInstanceState: Bundle?) { 128 super.onCreate(savedInstanceState) 129 setContentView(R.layout.activity_main) 130 131 _list = createList() 132 133 val lvCityList = findViewById<ListView>(R.id.lvCityList) 134 val from = arrayOf("name") 135 val to = intArrayOf(android.R.id.text1) 136 val adapter = SimpleAdapter(this@MainActivity, _list,android.R.layout.simple_list_item_1, 137 from,to) 138 lvCityList.adapter = adapter 139 lvCityList.onItemClickListener = ListItemClickListener() 140 } 141 142 //リストビューに表示させる天気ポイントリストデータを生成するメソッド 143 private fun createList(): MutableList<MutableMap<String,String>>{ 144 var list:MutableList<MutableMap<String,String>> = mutableListOf() 145 146 var city = mutableMapOf("name" to "北海道", "q" to "Hokkaido") 147 list.add(city) 148 149 city = mutableMapOf("name" to "東京", "q" to "Tokyo") 150 list.add(city) 151 152 city = mutableMapOf("name" to "山梨", "q" to "Yamanashi") 153 list.add(city) 154 155 city = mutableMapOf("name" to "大阪", "q" to "Osaka") 156 list.add(city) 157 158 city = mutableMapOf("name" to "神戸", "q" to "Kobe") 159 list.add(city) 160 161 city = mutableMapOf("name" to "鹿児島", "q" to "Kagoshima") 162 list.add(city) 163 164 return list 165 } 166 167 168 169 //リストがタップされた時の処理が記述されたリスナクラス 170 private inner class ListItemClickListener: AdapterView.OnItemClickListener{ 171 override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { 172 val item = _list.get(position) 173 val q = item.get("q") 174 q?.let{ 175 val urlFull = "$WEATHERINFO_URL&q=$q&appid=$APP_ID" 176 receiveWeatherInfo(urlFull) 177 } 178 } 179 } 180 181}

activity_main.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <TextView 10 android:id="@+id/tvWinfoTitle" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:layout_marginStart="8dp" 14 android:layout_marginTop="8dp" 15 android:layout_marginEnd="8dp" 16 android:text="@string/tv_winfo_title" 17 android:textSize="24sp" 18 app:layout_constraintEnd_toEndOf="parent" 19 app:layout_constraintStart_toStartOf="parent" 20 app:layout_constraintTop_toTopOf="@+id/glLvCityList" /> 21 22 <androidx.constraintlayout.widget.Guideline 23 android:id="@+id/glLvCityList" 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:orientation="horizontal" 27 app:layout_constraintGuide_percent="0.5" /> 28 29 <ListView 30 android:id="@+id/lvCityList" 31 android:layout_width="0dp" 32 android:layout_height="0dp" 33 app:layout_constraintBottom_toTopOf="@+id/glLvCityList" 34 app:layout_constraintEnd_toEndOf="parent" 35 app:layout_constraintStart_toStartOf="parent" 36 app:layout_constraintTop_toTopOf="parent" /> 37 38 <TextView 39 android:id="@+id/tvWeatherTelop" 40 android:layout_width="wrap_content" 41 android:layout_height="wrap_content" 42 android:layout_marginStart="8dp" 43 android:layout_marginTop="8dp" 44 android:textSize="20sp" 45 app:layout_constraintStart_toStartOf="parent" 46 app:layout_constraintTop_toBottomOf="@+id/tvWinfoTitle" /> 47 48 <TextView 49 android:id="@+id/tvWeatherDesc" 50 android:layout_width="0dp" 51 android:layout_height="0dp" 52 android:layout_marginStart="8dp" 53 android:layout_marginTop="8dp" 54 android:layout_marginEnd="8dp" 55 android:layout_marginBottom="8dp" 56 app:layout_constraintBottom_toBottomOf="parent" 57 app:layout_constraintEnd_toEndOf="parent" 58 app:layout_constraintStart_toStartOf="parent" 59 app:layout_constraintTop_toBottomOf="@+id/tvWeatherTelop" /> 60 61</androidx.constraintlayout.widget.ConstraintLayout>

strings.xml

1<resources> 2 <string name="app_name">お天気情報</string> 3 <string name="tv_winfo_title">お天気詳細</string> 4</resources>

試したこと

デバッグをしながら検証したところ、タップしたリストの値は読み取れている
ネットワークに接続が出来ていないことが原因と考えたが、スマホをネットワークに接続しても同様に落ちてしまった

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kynsk

2023/10/12 09:46

hoshi-takanori様ご回答ありがとうございます。 logcatを使って見てみました 赤字で以下のようなエラーが出力されたので調べてみたいと思います ありがとうございます。 Caused by: java.io.FileNotFoundException:
jimbe

2023/10/14 05:31

receiveWeatherInfo メソッドって非同期に通信していることになるのでしょうか?
kynsk

2023/10/19 12:02

非同期で通信している個所は@WokerThread以下のメソッドです!
guest

回答2

0

kotlin ならコルーチンなのかもしれませんがまだそこまで分からないので出来る範囲で動作をマネてみました。
java から変換して修正したので java っぽさが残っているかもしれませんが、何かの参考になれば…

MainActivity.kt

kotlin

1import android.os.Bundle 2import android.view.LayoutInflater 3import android.view.ViewGroup 4import android.widget.TextView 5import androidx.appcompat.app.AppCompatActivity 6import androidx.lifecycle.ViewModelProvider 7import androidx.recyclerview.widget.RecyclerView 8 9class MainActivity : AppCompatActivity() { 10 override fun onCreate(savedInstanceState: Bundle?) { 11 super.onCreate(savedInstanceState) 12 setContentView(R.layout.activity_main) 13 14 val weatherInfoViewModel = ViewModelProvider(this)[WeatherInfoViewModel::class.java] 15 weatherInfoViewModel.model = Model() 16 17 val cityList = findViewById<RecyclerView>(R.id.city_list) 18 cityList.adapter = CityAdapter(weatherInfoViewModel) 19 20 supportFragmentManager.beginTransaction() 21 .replace(R.id.fragment_container_view, WeatherInfoFragment()) 22 .commit() 23 } 24 25 //City 選択リスト. 選択するとその情報で WeatherInfoViewModel#requestWeatherInfo を呼び出す. 26 private class CityAdapter(private val weatherInfoViewModel: WeatherInfoViewModel) : RecyclerView.Adapter<CityAdapter.ViewHolder>() { 27 inner class ViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(android.R.layout.simple_list_item_1, parent, false)) { 28 private val text1 = itemView.findViewById<TextView>(android.R.id.text1).apply { 29 setOnClickListener { view -> weatherInfoViewModel.requestWeatherInfo(city!!) } 30 } 31 private var city: City? = null 32 fun bind(city: City) { 33 text1.text = city.name 34 this.city = city 35 } 36 } 37 38 private val itemList = listOf( 39 City("北海道", "Hokkaido"), 40 City("東京", "Tokyo"), 41 City("山梨", "Yamanashi"), 42 City("大阪", "Osaka"), 43 City("神戸", "Kobe"), 44 City("鹿児島", "Kagoshima") 45 ) 46 47 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(parent) 48 override fun getItemCount() = itemList.size 49 override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(itemList[position]) 50 } 51}

res/layout/activity_main.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <androidx.recyclerview.widget.RecyclerView 10 android:id="@+id/city_list" 11 android:layout_width="0dp" 12 android:layout_height="0dp" 13 app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" 14 app:layout_constraintBottom_toTopOf="@id/fragment_container_view" 15 app:layout_constraintEnd_toEndOf="parent" 16 app:layout_constraintStart_toStartOf="parent" 17 app:layout_constraintTop_toTopOf="parent" /> 18 19 <androidx.fragment.app.FragmentContainerView 20 android:id="@+id/fragment_container_view" 21 android:layout_width="0dp" 22 android:layout_height="0dp" 23 app:layout_constraintBottom_toBottomOf="parent" 24 app:layout_constraintEnd_toEndOf="parent" 25 app:layout_constraintStart_toStartOf="parent" 26 app:layout_constraintTop_toBottomOf="@id/city_list" 27 tools:layout="@layout/fragment_weather_info" /> 28 29</androidx.constraintlayout.widget.ConstraintLayout>

WeatherInfoFragment.kt

kotlin

1import android.os.Bundle 2import android.view.View 3import android.widget.TextView 4import androidx.fragment.app.Fragment 5import androidx.lifecycle.LiveData 6import androidx.lifecycle.MutableLiveData 7import androidx.lifecycle.ViewModel 8import androidx.lifecycle.ViewModelProvider 9import androidx.lifecycle.switchMap 10import java.text.MessageFormat 11 12//WeatherInfoViewModel の WeatherInfoLiveData から通知を受けて表示する. 13class WeatherInfoFragment : Fragment(R.layout.fragment_weather_info) { 14 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 15 super.onViewCreated(view, savedInstanceState) 16 17 val viewModel = ViewModelProvider(requireActivity())[WeatherInfoViewModel::class.java] 18 19 val telopText = view.findViewById<TextView>(R.id.telop_text) 20 val descriptionText = view.findViewById<TextView>(R.id.description_text) 21 22 val telopFormat = getString(R.string.telop_format) 23 val descriptionFormat = getString(R.string.description_format) 24 25 viewModel.weatherInfoLiveData.observe(viewLifecycleOwner) { 26 if (it == null) { 27 telopText.text = "" 28 descriptionText.text = "" 29 } else { 30 telopText.text = MessageFormat.format(telopFormat, it.cityName) 31 descriptionText.text = MessageFormat.format(descriptionFormat, it.weather, it.latitude, it.longitude) 32 } 33 } 34 } 35} 36 37class WeatherInfoViewModel : ViewModel() { 38 lateinit var model: Model 39 40 private val _cityLiveData = MutableLiveData<City?>() 41 42 private val _weatherInfoLiveData = _cityLiveData.switchMap { model?.requestWeatherInfo(it) } 43 val weatherInfoLiveData: LiveData<WeatherInfo?> get() = _weatherInfoLiveData 44 45 fun requestWeatherInfo(city: City) { 46 _cityLiveData.value = city 47 } 48}

res/layout/fragment_weather_info.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:layout_margin="8dp" 8 tools:context=".WeatherInfoFragment"> 9 10 <TextView 11 android:id="@+id/title_label" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:text="@string/wetherinfo_title" 15 android:textSize="24sp" 16 app:layout_constraintEnd_toEndOf="parent" 17 app:layout_constraintStart_toStartOf="parent" 18 app:layout_constraintTop_toTopOf="parent" /> 19 20 <TextView 21 android:id="@+id/telop_text" 22 android:layout_width="0dp" 23 android:layout_height="wrap_content" 24 android:layout_marginTop="8dp" 25 android:textAlignment="textStart" 26 android:textSize="20sp" 27 app:layout_constraintEnd_toEndOf="parent" 28 app:layout_constraintStart_toStartOf="parent" 29 app:layout_constraintTop_toBottomOf="@id/title_label" 30 tools:text="telop" /> 31 32 <TextView 33 android:id="@+id/description_text" 34 android:layout_width="0dp" 35 android:layout_height="0dp" 36 android:layout_marginTop="8dp" 37 app:layout_constraintBottom_toBottomOf="parent" 38 app:layout_constraintEnd_toEndOf="parent" 39 app:layout_constraintStart_toStartOf="parent" 40 app:layout_constraintTop_toBottomOf="@id/telop_text" 41 tools:text="description" /> 42 43</androidx.constraintlayout.widget.ConstraintLayout>

Model.kt

kotlin

1import androidx.lifecycle.LiveData 2import androidx.lifecycle.MutableLiveData 3import org.json.JSONException 4import org.json.JSONObject 5import java.net.HttpURLConnection 6import java.net.URL 7import java.nio.charset.StandardCharsets 8import java.util.concurrent.Executors 9 10class Model { 11 companion object { 12 private const val WEATHERINFO_URL = "https://api.openweathermap.org/data/2.5/weather?lang=ja" 13 private const val APP_ID = "c1a8424a8556a2fa057cffa058930173" 14 } 15 16 private val executorService = Executors.newSingleThreadExecutor() 17 18 //サーバから天気情報を取得し LiveData に入れる. 19 fun requestWeatherInfo(city: City?): LiveData<WeatherInfo?> { 20 val liveData = MutableLiveData<WeatherInfo?>() 21 if (city != null) executorService.submit(WeatherInfoReceiver(URL("${WEATHERINFO_URL}&q=${city.q}&appid=${APP_ID}"), liveData)) 22 return liveData 23 } 24} 25 26class WeatherInfoReceiver(private val url: URL, private val liveData: MutableLiveData<WeatherInfo?>) : Runnable { 27 override fun run() { 28 var con: HttpURLConnection? = null 29 try { 30 con = url.openConnection().apply { 31 connectTimeout = 1000 32 readTimeout = 1000 33 } as HttpURLConnection 34 liveData.postValue(parseJSON(con.inputStream.reader(StandardCharsets.UTF_8).readText())) 35 } catch (e: Exception) { 36 e.printStackTrace() 37 liveData.postValue(null) 38 } finally { 39 con?.disconnect() 40 } 41 } 42 43 @Throws(JSONException::class) 44 fun parseJSON(json: String): WeatherInfo { 45 val root = JSONObject(json) 46 val cityName = root.getString("name") 47 48 val coord = root.getJSONObject("coord") 49 val latitude = coord.getString("lat") 50 val longitude = coord.getString("lon") 51 52 val weather = root.getJSONArray("weather").getJSONObject(0).getString("description") 53 54 return WeatherInfo(cityName, latitude, longitude, weather) 55 } 56} 57 58class City(val name: String, val q: String) { 59 override fun toString() = 60 "City@${hashCode().toString(16)}[name=$name,q=$q]" 61} 62 63class WeatherInfo(val cityName: String, val latitude: String, val longitude: String, val weather: String) { 64 override fun toString() = 65 "WeatherInfo@${hashCode().toString(16)}[cityName=$cityName,latitude=$latitude,longitude=$longitude,weather=$weather]" 66}

res/values/strings.xml

xml

1<resources> 2 <string name="app_name">お天気情報</string> 3 <string name="wetherinfo_title">お天気詳細</string> 4 <string name="telop_format">{0}の天気</string> 5 <string name="description_format">現在は{0}です。\n緯度は{1}度で経度は{2}度です。</string> 6</resources>

AndroidManifest.xml に追加

<uses-permission android:name="android.permission.INTERNET"/>

build.gradle(:app) dependencies に追加

implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.2"

投稿2023/10/14 08:31

編集2023/10/14 08:44
jimbe

総合スコア12659

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

自己解決

hoshi-takanori様にご指摘していただいたようにlogcatから原因を特定し、解決することが出来ました
api参照時はurlの先頭にapi.をつける必要がありましたが抜けていました
誠にありがとうございました。

投稿2023/10/12 10:29

kynsk

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問