Böyle bir hata alıyorum nedeni nedir acaba
Bir yerlerde bir sey null
. Stack trace’in gosterdigi ilk satirdan baslayabilirsin.
Daha fazla yardim icin kodu ve hatayi yazi olarak paylasabilirsin.
package com.example.omercan_baymaz_json
import android.content.Intent
import android.os.AsyncTask
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.TextView
import android.widget.Toast
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONObject
import java.io.*
import java.lang.Exception
import java.net.HttpURLConnection
import java.net.SocketTimeoutException
import java.net.URL
import javax.net.ssl.HttpsURLConnection
import kotlin.concurrent.thread
class MainActivity : AppCompatActivity() {
var data:String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
omercan_baymaz_jsonAysncTask(this).execute()
}
fun calistir(r: String) {
var sonuc = Gson().fromJson(r, AracBilgisi::class.java)
Toast.makeText(this, sonuc.Ad+sonuc.konu, Toast.LENGTH_LONG).show()
var lstyeni: MutableList<String> = mutableListOf()
var lstid: MutableList<Int> = mutableListOf()
var bagla = ArrayAdapter(this, android.R.layout.simple_list_item_1, lstyeni)
lst_arac.adapter = bagla
var i=0;
for (arac:detay in sonuc.arac_bilgisi){
lstyeni.add("ID :"+arac.Id+"\n"+"\n"+"Marka :"+arac.Marka+"\n "+"\n"+"Model :"+arac.Model+"\n "+"\n"+"Yıl :"+arac.Yıl+"\n "+"\n"+"Motor Hacmi :"+arac.MotorHacmi+"\n "+"\n"+"Fiyat:"+arac.Fiyat)
}
lst_arac.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
val id = lstid[position]
val intent = Intent(this, AracBilgisi::class.java).apply {
putExtra("id", id)
}
var kod:Int=0
startActivityForResult(intent, kod)
}
}
}
class omercan_baymaz_jsonAysncTask(etkinlik: MainActivity) : AsyncTask<Unit, Unit, String>() {
val etkinlik: MainActivity? = etkinlik
override fun doInBackground(vararg params: Unit?): String? {
try {
val apiResponse =
URL("https://run.mocky.io/v3/a7d5e96a-e3d3-492b-a0be-f020c3a2eabb").readText()
return apiResponse
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
etkinlik?.calistir(result!!);
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.omercan_baymaz_json, PID: 13037
java.lang.NullPointerException
at com.example.omercan_baymaz_json.omercan_baymaz_jsonAysncTask.onPostExecute(MainActivity.kt:74)
at com.example.omercan_baymaz_json.omercan_baymaz_jsonAysncTask.onPostExecute(MainActivity.kt:55)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.-wrap1(Unknown Source:0)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Yardımlarınız için şimdiden teşekkürler
Nedeni result
'in null
gelmesi.