質問編集履歴

1

その後少し考えて操作していたら大きく変わった部分があるから。

2023/11/05 11:44

投稿

gogatsu
gogatsu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -16,14 +16,17 @@
16
16
  ### 発生している問題・エラーメッセージ
17
17
 
18
18
  ```
19
- Classifier 'LocationManager' does not have a companion object, and thus must be initialized here
19
+ Unresolved reference: getSystemService
20
+
20
21
  Unresolved reference: ACCESS_FINE_LOCATION
22
+
21
23
  Unresolved reference: ACCESS_FINE_LOCATION
22
- Unresolved reference: requestLocationUpdates
23
- Unresolved reference: requestLocationUpdates
24
+
25
+ <html>None of the following functions can be called with the arguments supplied:<br/>public open fun requestLocationUpdates(minTimeMs: Long, minDistanceM: Float, criteria: Criteria, pendingIntent: PendingIntent): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, locationRequest: LocationRequest, executor: Executor, listener: LocationListener): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, minTimeMs: Long, minDistanceM: Float, pendingIntent: PendingIntent): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, minTimeMs: Long, minDistanceM: Float, listener: LocationListener): Unit defined in android.location.LocationManager
26
+
27
+ <html>None of the following functions can be called with the arguments supplied:<br/>public open fun requestLocationUpdates(minTimeMs: Long, minDistanceM: Float, criteria: Criteria, pendingIntent: PendingIntent): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, locationRequest: LocationRequest, executor: Executor, listener: LocationListener): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, minTimeMs: Long, minDistanceM: Float, pendingIntent: PendingIntent): Unit defined in android.location.LocationManager<br/>public open fun requestLocationUpdates(provider: String, minTimeMs: Long, minDistanceM: Float, listener: LocationListener): Unit defined in android.location.LocationManager
28
+
24
29
  Unresolved reference: ACCESS_FINE_LOCATION
25
- Unresolved reference: removeUpdates
26
- Unresolved reference: Location
27
30
  ```
28
31
 
29
32
  ### 該当のソースコード
@@ -32,12 +35,14 @@
32
35
  package com.example.CompetitionApp
33
36
 
34
37
  //その他のことに使っているパッケージもあるため、今回のコードにおいて使用していないものもあります。
38
+ package com.example.CompetitionApp
39
+
35
40
  import android.content.Context
36
41
  import android.content.pm.PackageManager
42
+ import android.location.Location
37
43
  import android.location.LocationListener
38
44
  import android.location.LocationManager
39
45
  import android.os.Bundle
40
- import android.widget.TextView
41
46
  import androidx.appcompat.app.AppCompatActivity
42
47
  import androidx.core.app.ActivityCompat
43
48
  import androidx.navigation.fragment.NavHostFragment
@@ -50,21 +55,24 @@
50
55
 
51
56
 
52
57
  abstract class MainActivity : AppCompatActivity(), LocationListener {
58
+ //private lateinit var binding: FragmentRoutesearchBinding
59
+
60
+ private val manager = WorkManager.getInstance()
61
+
53
62
  private var locationmanager: LocationManager? = null
54
- private val textView: TextView? = null
55
63
 
56
64
  override fun onCreate(savedInstanceState: Bundle?) {
57
65
  super.onCreate(savedInstanceState)
58
66
  setContentView(R.layout.activity_main)
59
67
 
60
- //エラー1 Classifier 'LocationManager' does not have a companion object, and thus must be initialized here
68
+ //エラー Unresolved reference: getSystemService
61
- locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE)
69
+ locationmanager = (locationmanager) getSystemService(Context.LOCATION_SERVICE)
62
70
  }
63
71
 
64
72
  override fun onResume() {
65
73
  super.onResume()
66
74
 
67
- //エラー2、エラー3 Unresolved reference: ACCESS_FINE_LOCATION
75
+ //エラー2、3 Unresolved reference: ACCESS_FINE_LOCATION
68
76
  if (ActivityCompat.checkSelfPermission(
69
77
  this,
70
78
  Manifest.permission.ACCESS_FINE_LOCATION
@@ -77,8 +85,7 @@
77
85
  )
78
86
  return
79
87
  }
80
-
81
- //エラー4,エラー5 Unresolved reference: requestLocationUpdates
88
+ //エラー4,5 長いやつ
82
89
  locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this)
83
90
  locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 1, this)
84
91
  }
@@ -95,17 +102,15 @@
95
102
  ) {
96
103
  return
97
104
  }
98
-
99
- //エラー7 Unresolved reference: removeUpdates
100
- locationmanager.removeUpdates(this)
105
+ locationmanager!!.removeUpdates(this)
101
106
  }
102
107
  }
103
108
 
104
- //エラー8 Unresolved reference: Location
105
109
  override fun onLocationChanged(location: Location) {
106
110
  val text = "緯度:" + location.getLatitude() + "経度:" + location.getLongitude()
107
111
  }
108
112
  }
113
+
109
114
  ```
110
115
 
111
116
  ### 試したこと