Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. why I am not able to fetch data from Json in AndroidStudio

why I am not able to fetch data from Json in AndroidStudio

Scheduled Pinned Locked Moved Android
androidcomcryptographyjsonhelp
4 Posts 4 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jerry pugu
    wrote on last edited by
    #1

    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.Response

    class 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.Glide

    class 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
    
    Richard DeemingR J B 3 Replies Last reply
    0
    • J jerry pugu

      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.Response

      class 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.Glide

      class 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
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • J jerry pugu

        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.Response

        class 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.Glide

        class 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
        
        J Offline
        J Offline
        JakeClarke
        wrote on last edited by
        #3

        You can always seek help of other developers at very affordable prices Best ReactJs Developers for Hire in 2021 - Your Team in India[^]

        1 Reply Last reply
        0
        • J jerry pugu

          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.Response

          class 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.Glide

          class 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
          
          B Offline
          B Offline
          BrillMindz Tech
          wrote on last edited by
          #4

          thank you i also ahd the same problem i think these code lines would solve that

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups