why I am not able to fetch data from Json in AndroidStudio
-
package com.example.cryptotracker
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Responseclass MainActivity : AppCompatActivity() {
private lateinit var mAdapter :CryptoAdapter
private var crypto1 = mutableListOf()override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) mAdapter = CryptoAdapter(this,crypto1) recyclerView.adapter = mAdapter recyclerView.layoutManager = LinearLayoutManager(this) getCrypto() } private fun getCrypto() { val crypto:Call = CryptoService.cryptoInstance.getExchanges() crypto.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val crypto:CryptoList? = response.body() if(crypto!=null) { Log.d("THISSSSS",crypto.toString()) crypto1.addAll(crypto.crypto1) mAdapter.notifyDataSetChanged() } } override fun onFailure(call: Call, t: Throwable) { Log.d("ERRRRRROR","ERROR IN FETCHING",t) } } ) }
}
package com.example.cryptotracker
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glideclass CryptoAdapter(val context:Context, val crypto1:List ):RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CryptoViewHolder {
val view:View = LayoutInflater.from(context).inflate(R.layout.item_crypto,parent,false)
return CryptoViewHolder(view)
}override fun onBindViewHolder(holder: CryptoViewHolder, position: Int) { val current\_item:Crypto = crypto1\[position\] holder.cryptoName.text = current\_item.name holder.cryptoCountry.text = current\_item.country holder.cryptoUrl.te
-
package com.example.cryptotracker
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Responseclass MainActivity : AppCompatActivity() {
private lateinit var mAdapter :CryptoAdapter
private var crypto1 = mutableListOf()override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) mAdapter = CryptoAdapter(this,crypto1) recyclerView.adapter = mAdapter recyclerView.layoutManager = LinearLayoutManager(this) getCrypto() } private fun getCrypto() { val crypto:Call = CryptoService.cryptoInstance.getExchanges() crypto.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val crypto:CryptoList? = response.body() if(crypto!=null) { Log.d("THISSSSS",crypto.toString()) crypto1.addAll(crypto.crypto1) mAdapter.notifyDataSetChanged() } } override fun onFailure(call: Call, t: Throwable) { Log.d("ERRRRRROR","ERROR IN FETCHING",t) } } ) }
}
package com.example.cryptotracker
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glideclass CryptoAdapter(val context:Context, val crypto1:List ):RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CryptoViewHolder {
val view:View = LayoutInflater.from(context).inflate(R.layout.item_crypto,parent,false)
return CryptoViewHolder(view)
}override fun onBindViewHolder(holder: CryptoViewHolder, position: Int) { val current\_item:Crypto = crypto1\[position\] holder.cryptoName.text = current\_item.name holder.cryptoCountry.text = current\_item.country holder.cryptoUrl.te
jerry pugu wrote:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
The JSON you are trying to deserialize doesn't match the object graph you are trying to deserialize it to. Specifically, you are expecting JSON that represents a single object, but the JSON you are trying to deserialize represents an array of objects.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
package com.example.cryptotracker
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Responseclass MainActivity : AppCompatActivity() {
private lateinit var mAdapter :CryptoAdapter
private var crypto1 = mutableListOf()override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) mAdapter = CryptoAdapter(this,crypto1) recyclerView.adapter = mAdapter recyclerView.layoutManager = LinearLayoutManager(this) getCrypto() } private fun getCrypto() { val crypto:Call = CryptoService.cryptoInstance.getExchanges() crypto.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val crypto:CryptoList? = response.body() if(crypto!=null) { Log.d("THISSSSS",crypto.toString()) crypto1.addAll(crypto.crypto1) mAdapter.notifyDataSetChanged() } } override fun onFailure(call: Call, t: Throwable) { Log.d("ERRRRRROR","ERROR IN FETCHING",t) } } ) }
}
package com.example.cryptotracker
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glideclass CryptoAdapter(val context:Context, val crypto1:List ):RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CryptoViewHolder {
val view:View = LayoutInflater.from(context).inflate(R.layout.item_crypto,parent,false)
return CryptoViewHolder(view)
}override fun onBindViewHolder(holder: CryptoViewHolder, position: Int) { val current\_item:Crypto = crypto1\[position\] holder.cryptoName.text = current\_item.name holder.cryptoCountry.text = current\_item.country holder.cryptoUrl.te
You can always seek help of other developers at very affordable prices Best ReactJs Developers for Hire in 2021 - Your Team in India[^]
-
package com.example.cryptotracker
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Responseclass MainActivity : AppCompatActivity() {
private lateinit var mAdapter :CryptoAdapter
private var crypto1 = mutableListOf()override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) mAdapter = CryptoAdapter(this,crypto1) recyclerView.adapter = mAdapter recyclerView.layoutManager = LinearLayoutManager(this) getCrypto() } private fun getCrypto() { val crypto:Call = CryptoService.cryptoInstance.getExchanges() crypto.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val crypto:CryptoList? = response.body() if(crypto!=null) { Log.d("THISSSSS",crypto.toString()) crypto1.addAll(crypto.crypto1) mAdapter.notifyDataSetChanged() } } override fun onFailure(call: Call, t: Throwable) { Log.d("ERRRRRROR","ERROR IN FETCHING",t) } } ) }
}
package com.example.cryptotracker
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glideclass CryptoAdapter(val context:Context, val crypto1:List ):RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CryptoViewHolder {
val view:View = LayoutInflater.from(context).inflate(R.layout.item_crypto,parent,false)
return CryptoViewHolder(view)
}override fun onBindViewHolder(holder: CryptoViewHolder, position: Int) { val current\_item:Crypto = crypto1\[position\] holder.cryptoName.text = current\_item.name holder.cryptoCountry.text = current\_item.country holder.cryptoUrl.te
thank you i also ahd the same problem i think these code lines would solve that