Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApiCalls {
- val client = OkHttpClient()
- val list: ArrayList<VehicleListModel>? = null
- public fun getEnquiryList(id:String): ArrayList<EnquiryModel>? {
- return null
- }
- public fun getVehicleList(): ArrayList<VehicleListModel> {
- val body = FormBody.Builder()
- .build()
- val request = Request.Builder()
- .post(body)
- .url(URLs.URL_GET_VEHICLE_LIST)
- .build()
- val callGetVehicleList = client.newCall(request)
- callGetVehicleList?.enqueue(object : Callback {
- override fun onFailure(call: Call?, e: IOException?) {
- if (call == null || call.isCanceled)
- return
- }
- override fun onResponse(call: Call?, response: Response?) {
- if (call == null || call.isCanceled)
- return
- val resp = response?.body()?.string()
- try {
- val jo = JSONObject(resp)
- val message = jo.getJSONArray("VehicleModelList")
- for (i in 0 until message.length()) {
- val json = message.getJSONObject(i)
- val vehicleListId = json.getString("_id")
- val vehicleListName = json.getString("vehicle_model_name")
- val vehicle = VehicleListModel(vehicleListId, vehicleListName)
- if (list != null) {
- list.add(vehicle)
- }
- Log.e("....................",vehicleListId)
- }
- } catch (e: Exception) {
- }
- }
- })
- return list!!
- }
- list= ApiCalls().getVehicleList()
- for (i in 0 until list.size)
- {
- labels.add(list[i].vehicleName)
- }
- val adapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, labels)
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
- vehiclelist.adapter = adapter
- FATAL EXCEPTION: main
- Process: abc.com.app, PID: 23077
- kotlin.KotlinNullPointerException
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement