Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class ApiCalls {
  2. val client = OkHttpClient()
  3. val list: ArrayList<VehicleListModel>? = null
  4. public fun getEnquiryList(id:String): ArrayList<EnquiryModel>? {
  5. return null
  6. }
  7. public fun getVehicleList(): ArrayList<VehicleListModel> {
  8.  
  9.  
  10. val body = FormBody.Builder()
  11. .build()
  12. val request = Request.Builder()
  13. .post(body)
  14. .url(URLs.URL_GET_VEHICLE_LIST)
  15. .build()
  16. val callGetVehicleList = client.newCall(request)
  17. callGetVehicleList?.enqueue(object : Callback {
  18. override fun onFailure(call: Call?, e: IOException?) {
  19. if (call == null || call.isCanceled)
  20. return
  21.  
  22. }
  23.  
  24. override fun onResponse(call: Call?, response: Response?) {
  25. if (call == null || call.isCanceled)
  26. return
  27. val resp = response?.body()?.string()
  28.  
  29. try {
  30.  
  31.  
  32. val jo = JSONObject(resp)
  33. val message = jo.getJSONArray("VehicleModelList")
  34.  
  35. for (i in 0 until message.length()) {
  36. val json = message.getJSONObject(i)
  37. val vehicleListId = json.getString("_id")
  38. val vehicleListName = json.getString("vehicle_model_name")
  39. val vehicle = VehicleListModel(vehicleListId, vehicleListName)
  40. if (list != null) {
  41. list.add(vehicle)
  42. }
  43. Log.e("....................",vehicleListId)
  44. }
  45.  
  46. } catch (e: Exception) {
  47.  
  48.  
  49. }
  50. }
  51.  
  52. })
  53.  
  54.  
  55. return list!!
  56. }
  57.  
  58. list= ApiCalls().getVehicleList()
  59. for (i in 0 until list.size)
  60. {
  61. labels.add(list[i].vehicleName)
  62. }
  63. val adapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, labels)
  64.  
  65. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
  66.  
  67. vehiclelist.adapter = adapter
  68.  
  69. FATAL EXCEPTION: main
  70. Process: abc.com.app, PID: 23077
  71. kotlin.KotlinNullPointerException
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement