Click here to Skip to main content
15,436,928 members
Home / Discussions / Android
   

Android

 
QuestionAndroid: advice on method to wake up CPU from sleep, carry out a task then go back to sleep Pin
Member 152740822-Jul-21 20:58
MemberMember 152740822-Jul-21 20:58 
AnswerRe: Android: advice on method to wake up CPU from sleep, carry out a task then go back to sleep Pin
Mycroft Holmes3-Jul-21 13:25
professionalMycroft Holmes3-Jul-21 13:25 
GeneralRe: Android: advice on method to wake up CPU from sleep, carry out a task then go back to sleep Pin
Peter_in_27803-Jul-21 14:24
professionalPeter_in_27803-Jul-21 14:24 
GeneralRe: Android: advice on method to wake up CPU from sleep, carry out a task then go back to sleep Pin
Mycroft Holmes5-Jul-21 12:27
professionalMycroft Holmes5-Jul-21 12:27 
QuestionHow can I make an android app for Amazon Store affiliate deal & coupons? Pin
Amit Saha 202122-Jun-21 0:05
MemberAmit Saha 202122-Jun-21 0:05 
AnswerRe: How can I make an android app for Amazon Store affiliate deal & coupons? Pin
codelexer22-Jun-21 18:41
Membercodelexer22-Jun-21 18:41 
QuestionHow to set proportional distance between two controls? Pin
Alex Dunlop19-Jun-21 6:41
MemberAlex Dunlop19-Jun-21 6:41 
Questionwhy I am not able to fetch data from Json in AndroidStudio Pin
jerry pugu27-May-21 1:55
Memberjerry pugu27-May-21 1:55 
<pre lang="Kotlin"><pre>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<Crypto>()

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<CryptoList> = CryptoService.cryptoInstance.getExchanges()
crypto.enqueue(object : Callback<CryptoList> {
override fun onResponse(call: Call<CryptoList>, response: Response<CryptoList>) {
val crypto:CryptoList? = response.body()
if(crypto!=null)
{
Log.d("THISSSSS",crypto.toString())
crypto1.addAll(crypto.crypto1)
mAdapter.notifyDataSetChanged()

}
}

override fun onFailure(call: Call<CryptoList>, t: Throwable) {
Log.d("ERRRRRROR","ERROR IN FETCHING",t)
}
} )
}
}</pre></pre>

<pre lang="Kotlin"><pre>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<Crypto> ):RecyclerView.Adapter<CryptoViewHolder>() {
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.text = current_item.url
holder.cryptoVolume.text = current_item.trade_volume_24h_btc
Glide.with(context).load(current_item.image).into(holder.cryptoImage)
}

override fun getItemCount(): Int {
return crypto1.size
}

}


class CryptoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

var cryptoName = itemView.findViewById<TextView>(R.id.cryptoName)
var cryptoImage = itemView.findViewById<ImageView>(R.id.cryptoImage)
var cryptoCountry = itemView.findViewById<TextView>(R.id.cryptoCountry)
var cryptoUrl = itemView.findViewById<TextView>(R.id.cryptoUrl)
var cryptoVolume = itemView.findViewById<TextView>(R.id.cryptoVolume)



}</pre></pre>

<pre lang="Kotlin"><pre>package com.example.cryptotracker

import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.http.GET
import retrofit2.create
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Query

const val BASE_URL = "https://api.coingecko.com/"


interface CryptoInteface {
@GET("api/v3/exchanges")
fun getExchanges(): Call<CryptoList>
}

object CryptoService {
val cryptoInstance: CryptoInteface

init {
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
.build()

cryptoInstance = retrofit.create(CryptoInteface::class.java)


}
}</pre></pre>

<pre lang="Kotlin"><pre>package com.example.cryptotracker

data class CryptoList (
val crypto1:List<Crypto>
)</pre></pre>

<pre lang="Kotlin">package com.example.cryptotracker

data class Crypto (
val name:String,
val country:String,
val url:String,
val image:String,
val trade_volume_24h_btc:String,
val trade_volume_24h_btc_normalized:String

)</pre>


<pre lang="text">com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:40)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:153)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:386)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:40)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:153)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764) </pre>
AnswerRe: why I am not able to fetch data from Json in AndroidStudio Pin
Richard Deeming27-May-21 3:06
mveRichard Deeming27-May-21 3:06 
AnswerRe: why I am not able to fetch data from Json in AndroidStudio Pin
BrillMindz Tech20-Sep-21 21:43
MemberBrillMindz Tech20-Sep-21 21:43 
QuestionConcepts for app development Pin
satyendra109015-May-21 19:43
Membersatyendra109015-May-21 19:43 
QuestionHow to create a semi-transparent frame in Xamarin (XAML code)? Pin
Alex Dunlop13-May-21 19:59
MemberAlex Dunlop13-May-21 19:59 
AnswerRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Richard MacCutchan13-May-21 21:04
mveRichard MacCutchan13-May-21 21:04 
GeneralRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Alex Dunlop13-May-21 23:03
MemberAlex Dunlop13-May-21 23:03 
GeneralRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Richard MacCutchan13-May-21 23:22
mveRichard MacCutchan13-May-21 23:22 
GeneralRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Alex Dunlop13-May-21 23:53
MemberAlex Dunlop13-May-21 23:53 
GeneralRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Richard MacCutchan14-May-21 0:57
mveRichard MacCutchan14-May-21 0:57 
AnswerRe: How to create a semi-transparent frame in Xamarin (XAML code)? Pin
Gerry Schmitz14-May-21 9:42
mveGerry Schmitz14-May-21 9:42 
QuestionHow do I fire up an Android Emulator in Android Studio? Pin
priyamtheone6-May-21 8:14
Memberpriyamtheone6-May-21 8:14 
QuestionRe: How do I fire up an Android Emulator in Android Studio? Pin
David Crow9-May-21 16:23
MemberDavid Crow9-May-21 16:23 
AnswerRe: How do I fire up an Android Emulator in Android Studio? Pin
priyamtheone11-May-21 9:12
Memberpriyamtheone11-May-21 9:12 
AnswerRe: How do I fire up an Android Emulator in Android Studio? Pin
Gerry Schmitz14-May-21 9:53
mveGerry Schmitz14-May-21 9:53 
GeneralRe: How do I fire up an Android Emulator in Android Studio? Pin
priyamtheone15-May-21 5:55
Memberpriyamtheone15-May-21 5:55 
AnswerRe: How do I fire up an Android Emulator in Android Studio? Pin
JakeClarke25-May-21 3:19
professionalJakeClarke25-May-21 3:19 
GeneralRe: How do I fire up an Android Emulator in Android Studio? Pin
priyamtheone27-May-21 6:10
Memberpriyamtheone27-May-21 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.