мое приложение работало отлично. Теперь я сделал обновление kotlin, и он выдает мне эту ошибку:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hdmc.smartristraveller, PID: 4788
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter location
at com.hdmc.smartristraveller.fahrplanmap$onCreate$1.onSuccess(Unknown Source:2)
at com.hdmc.smartristraveller.fahrplanmap$onCreate$1.onSuccess(fahrplanmap.kt:22)
at com.google.android.gms.tasks.zzn.run(Unknown Source:27)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Я искал везде, но не мог найти нулевой параметр, кто-нибудь знает, что может вызвать это исключение?
Вот мой код для этого класса:
class fahrplanmap : AppCompatActivity() {
var webservices = webservices()
var StationID = IntArray(300)
var haltestellen_name : ArrayList<String> = ArrayList()
var haltestellen_lat: DoubleArray = DoubleArray(300) //all busstops
var haltestellen_lon: DoubleArray = DoubleArray(300) //all busstops
var StopDistances = DoubleArray(300)
var Haltestellen : ArrayList<String> = ArrayList()
var time = Handler()
var latitude = 0.0
var longitude = 0.0
companion object {
private const val LOCATION_PERMISSION_REQUEST_CODE = 1
}
private lateinit var fusedLocationClient: FusedLocationProviderClient
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) { //wenn Bottom Navigationbar berührt wird
R.id.navigation_Auskunft -> {
// message.setText(R.string.title_Auskunft)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Abfahrtsmonitor -> {
// message.setText(R.string.title_Abfahrtsmonitor)
val intent = Intent(this, Abfahrtsmonitor::class.java) //Opens fahrplanmap Class
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Karte -> {
// message.setText(R.string.title_Karte)
val intent = Intent(this, MapsAnzeigeActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_Meldungen -> {
message.setText(R.string.title_meldungen)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_weiteres -> {
message.setText(R.string.title_weiteres)
return@OnNavigationItemSelectedListener true
}
}
false
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_fahrplanmap)
val navigation = findViewById<BottomNavigationView>(R.id.navigation) // findViewById<BottomNavigationView>(R.id.navigation)
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
Haltestellen.clear()
Recycleview2.layoutManager = LinearLayoutManager(this)
Recycleview2.adapter = listadapter(haltestellen_name, this)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), fahrplanmap.LOCATION_PERMISSION_REQUEST_CODE)
return
}
val locationManager = getSystemService(Context.LOCATION_SERVICE) as
LocationManager
// Define a listener that responds to location updates
val locationListener = object : LocationListener {
override fun onLocationChanged(location: Location) {
// Called when a new location is found by the network location provider.
println("GPS WOrks yeahhhh")
}
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
}
override fun onProviderEnabled(provider: String) {
}
override fun onProviderDisabled(provider: String) {
}
}
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0f,locationListener)
fusedLocationClient.lastLocation
.addOnSuccessListener { location: Location ->
if( location != null) {
latitude = location?.latitude
longitude = location?.longitude
println(latitude)
println(longitude)
println("gps?")
StopsFromWebservice().execute()
}
}
println(fusedLocationClient.lastLocation)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
fun FindClosestStops(){
for (i in 0..haltestellen_lat.size-1){
var x=0.0
var y=0.0
var distance = 0.0
x= (haltestellen_lat[i]-latitude)*(haltestellen_lat[i]-latitude)
y= (haltestellen_lon[i]-longitude)*(haltestellen_lon[i]-longitude)
distance = sqrt(x+y)
StopDistances[i]= distance
Haltestellen.add(distance.toString())
}
SortDistance()
time.post(UpdateView);
}
inner class StopsFromWebservice : AsyncTask<String, String, String>() { //Todo buslinien noch richtig stellen, von busroute zu lineid!!
override fun doInBackground(vararg p0: String?): String {
webservices.get_Haltestellen()
StationID = webservices.StationID
haltestellen_name = webservices.Haltestellen
haltestellen_lat = webservices.haltestellen_lat
haltestellen_lon = webservices.haltestellen_lon //todo schauen ob hintergrundprozess nötig
FindClosestStops()
return ""
}
}
private val UpdateView = object : Runnable {
override fun run() {
Recycleview2.adapter.notifyDataSetChanged() //draws the route on maps
time.postDelayed(this, 1000)
}
}
fun deleteTimer(){
time.removeCallbacks(UpdateView);
}
fun SortDistance(){
var sorted = false
var i = 0
var k = 0
while(k<haltestellen_name.size) {
while (i < haltestellen_name.size - 1) {
if (Haltestellen[i] > Haltestellen[i + 1]) {
var dummy1 = Haltestellen[i]
var dummy2 = haltestellen_name[i]
Haltestellen[i] = Haltestellen[i + 1]
haltestellen_name[i] = haltestellen_name[i + 1]
Haltestellen[i + 1] = dummy1
haltestellen_name[i + 1] = dummy2
}
i++
}
k++
i=0
println(k)
}
deleteTimer()
}
}
Я прошу прощения за этот неопределенный вопрос, что может вызвать нулевое исключение? Это даже не начало, что я мог искать с отладчиком. Я попытался удалить код обработки gps, но он ничего не изменил
UPDATE:
Я могу запустить приложение один раз на эмуляторе, ошибка появляется со второго использования и далее