Kotlin “如何修复异常”;非空即为空;?
我的应用程序运行得非常好。现在我进行了kotlin更新,它向我抛出了以下错误:Kotlin “如何修复异常”;非空即为空;?,kotlin,Kotlin,我的应用程序运行得非常好。现在我进行了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.checkPar
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)
我到处搜索,但找不到null参数,有人知道什么会引发此异常吗
下面是我的此类代码:
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()
}
}
类fahrplanmap:AppCompatActivity(){
var webservices=webservices()
var StationID=IntArray(300)
var haltestellen_name:ArrayList=ArrayList()
var haltestellen_lat:DoubleArray=DoubleArray(300)//所有总线停止
var haltestellen_lon:DoubleArray=DoubleArray(300)//所有总线停止
var停止距离=双阵列(300)
var Haltestellen:ArrayList=ArrayList()
var time=Handler()
var纬度=0.0
var经度=0.0
伴星{
私有const val LOCATION\u PERMISSION\u REQUEST\u CODE=1
}
私有lateinit变量fusedLocationClient:FusedLocationProviderClient
private val mOnNavigationItemSelectedListener=BottomNavigationView.OnNavigationItemSelectedListener{item->
当(item.itemId){//wenn底部导航栏berührt wird
R.id.navigation\u Auskunft->{
//message.setText(R.string.title_Auskunft)
return@OnNavigationItemSelectedListener真的
}
R.id.navigation\u Abfahrtsmonitor->{
//message.setText(R.string.title_Abfahrtsmonitor)
val intent=intent(这是Abfahrtsmonitor::class.java)//打开fahrplanmap类
星触觉(意图)
return@OnNavigationItemSelectedListener真的
}
R.id.navigation\u卡丁车->{
//message.setText(R.string.title_Karte)
val intent=intent(这是MapsAnzeigeActivity::class.java)
星触觉(意图)
return@OnNavigationItemSelectedListener真的
}
R.id.navigation\u Meldungen->{
message.setText(R.string.title\u meldungen)
return@OnNavigationItemSelectedListener真的
}
R.id.navigation_weiteres->{
message.setText(R.string.title\u weiteres)
return@OnNavigationItemSelectedListener真的
}
}
假的
}
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_fahrplanmap)
val navigation=findviewbyd(R.id.navigation)//findviewbyd(R.id.navigation)
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
Haltestellen.clear()
Recycleview2.layoutManager=LinearLayoutManager(此)
Recycleview2.adapter=listadapter(haltestellen_名称,此名称)
fusedLocationClient=LocationServices.getFusedLocationProviderClient(此)
如果(ActivityCompat.checkSelfPermission)(此,
android.Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u provided){
ActivityCompat.requestPermissions(此,
arrayOf(android.Manifest.permission.ACCESS\u FINE\u LOCATION)、fahrplanmap.LOCATION\u permission\u REQUEST\u CODE)
返回
}
val locationManager=getSystemService(Context.LOCATION\u服务)作为
位置经理
//定义响应位置更新的侦听器
val locationListener=对象:locationListener{
覆盖已更改的位置(位置:位置){
//当网络位置提供程序找到新位置时调用。
println(“全球定位系统工作正常”)
}
重写fun onStatusChanged(提供程序:字符串,状态:Int,附加:Bundle){
}
重写onProviderEnabled(提供程序:字符串){
}
override onProviderDisabled(提供程序:字符串){
}
}
//向位置管理器注册侦听器以接收位置更新
locationManager.RequestLocationUpdate(locationManager.NETWORK\u提供程序,0,0f,locationListener)
fusedLocationClient.lastLocation
.addOnSuccessListener{location:location->
如果(位置!=null){
纬度=位置?纬度
经度=位置?经度
println(纬度)
println(经度)
println(“gps?”)
StopsFromWebservice().execute()
}
}
println(fusedLocationClient.lastLocation)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
趣味FindClosestStops(){
适用于(i英寸0..haltestellen_lat.尺寸-1){
var x=0.0
变量y=0.0
var距离=0.0
x=(haltestellen_lat[i]-纬度)*(haltestellen_lat[i]-纬度)
y=(haltestellen_-lon[i]-经度)*(haltestellen_-lon[i]-经度)
距离=平方米(x+y)
停车距离[i]=距离
Haltestellen.add(distance.toString())
}
SortDistance()
time.post(UpdateView);
}
内部类StopsFromWebservice:AsyncTask(){//Todo Buslinen noch richtig stellen,von busroute zu lineid!!
重写fun doInBackground(vararg p0:String?:String){
webservices.get_Haltestellen()
StationID=webservices.StationID
haltestellen_name=webservices.haltestellen
haltestellen\u lat=webservices.haltestellen\u lat
haltestellen_lon=webservices.haltestellen_lon//todo schauen ob hintergrandprozess nötig
FindClosestStops()
返回“”
}
}
private val UpdateView=对象:可运行{
覆盖趣味跑(){
Recycleview2.adapter.notifyDataSetChanged()//在地图上绘制路线
时间延迟(本次,1000)
}
}
乐趣删除计时器(){
time.removeCallbacks(UpdateView);
}
乐趣{
var=false
变量i=0
var k=0
而(k-Haltestellen[i+1]){
var dummy1=Haltestellen[i]
var dummy2=haltestellen_名称[i]