Good morning everyone,
I have a problem with Android Studio's Moshi library for Kotlin. I don't quite understand why, but it tells me that the constructor of the JsonAdapter class for the adapter that is going to be populated with JSON data cannot be instantiated.
com.sanz.mbtigrid.mbtidataclasses.MBTITypesDataJsonAdapter.<init> []
at java.lang.Class.getConstructor0(Class.java:2332)
at java.lang.Class.getDeclaredConstructor(Class.java:2170)
at com.squareup.moshi.internal.Util.generatedAdapter(Util.java:583)
at com.squareup.moshi.StandardJsonAdapters$1.create(StandardJsonAdapters.java:61)
at com.squareup.moshi.Moshi.adapter(Moshi.java:146)
at com.squareup.moshi.Moshi.adapter(Moshi.java:106)
at com.squareup.moshi.Moshi.adapter(Moshi.java:80)
at com.sanz.mbtigrid.MainActivity.<init>(MainActivity.kt:499)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2022-09-18 13:58:27.009 17327-17327/com.sanz.mbtigrid I/Process: Sending signal. PID: 17327 SIG: 9
The code fails at line 499 of MainActivity.kt:
private val mbtiTypesDataAdapter: JsonAdapter<MBTITypesData> = moshi.adapter(MBTITypesData::class.java)
Here is the MainActivity.kt:
package com.sanz.mbtigrid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.*
import com.sanz.mbtigrid.mbtidataclasses.MBTITypesData
import com.sanz.mbtigrid.mbtidataclasses.MBTITypesDataJsonAdapter
import com.sanz.mbtigrid.changegriddata.*
import com.sanz.mbtigrid.mbtidataclasses.MBTITypesDataItem
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import kotlin.collections.ArrayList
class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
private var arrayList: ArrayList<MBTITypesDataItem>? = null
private var gridView: GridView? = null
private var mbtiTypesDataJsonAdapter: MBTITypesDataJsonAdapter? = null
private val mbtiTypesList: List<String> = listOf(
"ENFJ",
"ETC"
)
private val sidesOfTheMindList: List<String> = listOf(
"Ego-Ego",
"ETC"
)
private var percentageList: MutableList<Int> = mutableListOf(
0,
0,
40,
30,
100,
80,
40,
50,
60,
60,
0,
0,
30,
20,
40,
50
)
private var provideFunctionOneList: MutableList<String> = mutableListOf(
"",
"",
"Ti",
"Ti",
"Ni",
"Ni",
"Ni",
"Ni",
"Ni",
"Ni",
"",
"",
"Ni",
"Ni",
"Ti",
"Ti"
)
private var provideFunctionTwoList: MutableList<String> = mutableListOf(
"",
"",
"",
"",
"Ti",
"Ti",
"",
"",
"Ti",
"Ti",
"",
"",
"",
"",
"",
""
)
private var recieveFunctionOneList: MutableList<String> = mutableListOf(
"",
"",
"Fi",
"Fi",
"Fi",
"Fi",
"Si",
"Si",
"Fi",
"Fi",
"",
"",
"Si",
"Si",
"Fi",
"Fi"
)
private var recieveFunctionTwoList: MutableList<String> = mutableListOf(
"",
"",
"",
"",
"Si",
"Si",
"",
"",
"Si",
"Si",
"",
"",
"",
"",
"",
""
)
private var provideFunctionOnePercentagesList: MutableList<Int> = mutableListOf(
0,
0,
80,
60,
100,
80,
80,
100,
60,
40,
0,
0,
60,
40,
80,
100
)
private var provideFunctionTwoPercentagesList: MutableList<Int> = mutableListOf(
0,
0,
0,
0,
100,
80,
0,
0,
60,
80,
0,
0,
0,
0,
0,
0
)
private var recieveFunctionOnePercentagesList: MutableList<Int> = mutableListOf(
0,
0,
80,
60,
100,
80,
80,
100,
60,
80,
0,
0,
60,
40,
80,
100
)
private var recieveFunctionTwoPercentagesList: MutableList<Int> = mutableListOf(
0,
0,
0,
0,
100,
80,
0,
0,
60,
40,
0,
0,
0,
0,
0,
0
)
private val gridData: GridData = GridData(percentageList,
provideFunctionOneList,
provideFunctionTwoList,
recieveFunctionOneList,
recieveFunctionTwoList,
provideFunctionOnePercentagesList,
provideFunctionTwoPercentagesList,
recieveFunctionOnePercentagesList,
recieveFunctionTwoPercentagesList)
// LOGIC
// Load all the data into a variable
private val allDataJSON = """
{
"INFJ_ego_ego": {"INFJ": [0, {}, {}, "NOTHING"], "INFP": [3.2, {"Ni": 4, "Ti": 4}, {"Fi": 4, "Si": 4}, "PROVIDE AND RECIEVE"], "INTJ": [1.6, {"Ti": 4}, {"Fi": 4}, "PROVIDE AND RECIEVE"], "INTP": [1.6, {"Ni": 4}, {"Si": 4}, "PROVIDE AND RECIEVE"], "ISFJ": [0.8, {"Ni": 2}, {"Si": 2}, "PROVIDE AND RECIEVE"], "ISFP": [1.6, {"Ti": 4}, {"Fi": 4}, "PROVIDE AND RECIEVE"], "ISTJ": [2.4, {"Ni": 2, "Ti": 4}, {"Fi": 4, "Si": 2}, "PROVIDE AND RECIEVE"], "ISTP": [0, {}, {}, "NOTHING"], "ENFJ": [0, {}, {}, "NOTHING"], "ENFP": [4, {"Ni": 5, "Ti": 5}, {"Fi": 5, "Si": 5}, "PROVIDE AND RECIEVE"], "ENTJ": [1.2, {"Ti": 3}, {"Fi": 3}, "PROVIDE AND RECIEVE"], "ENTP": [2, {"Ni": 5}, {"Si": 5}, "PROVIDE AND RECIEVE"], "ESFJ": [1.2, {"Ni": 3}, {"Si": 3}, "PROVIDE AND RECIEVE"], "ESFP": [2, {"Ti": 5}, {"Fi": 5}, "PROVIDE AND RECIEVE"], "ESTJ": [2.4, {"Ni": 3, "Ti": 3}, {"Fi": 3, "Si": 3}, "PROVIDE AND RECIEVE"], "ESTP": [0, {}, {}, "NOTHING"]},
"INFJ_ego_shadow": {"INFJ": [4, {"Ni": 5, "Ti": 5}, {"Fi": 5, "Si": 5}, "PROVIDE AND RECIEVE"], "INFP": [0, {}, {}, "NOTHING"], "INTJ": [2, {"Ni": 5}, {"Si": 5}, "PROVIDE AND RECIEVE"], "INTP": [1.2, {"Ti": 3}, {"Fi": 3}, "PROVIDE AND RECIEVE"], "ISFJ": [2, {"Ti": 5}, {"Fi": 5}, "PROVIDE AND RECIEVE"], "ISFP": [1.2, {"Ni": 3}, {"Si": 3}, "PROVIDE AND RECIEVE"], "ISTJ": [0, {}, {}, "NOTHING"], "ISTP": [2.4, {"Ni": 3, "Ti": 3}, {"Fi": 3, "Si": 3}, "PROVIDE AND RECIEVE"], "ENFJ": [3.2, {"Ni": 4, "Ti": 4}, {"Fi": 4, "Si": 4}, "PROVIDE AND RECIEVE"], "ENFP": [0, {}, {}, "NOTHING"], "ENTJ": [1.6, {"Ni": 4}, {"Si": 4}, "PROVIDE AND RECIEVE"], "ENTP": [1.6, {"Ti": 4}, {"Fi": 4}, "PROVIDE AND RECIEVE"], "ESFJ": [1.6, {"Ti": 4}, {"Fi": 4}, "PROVIDE AND RECIEVE"], "ESFP": [0.8, {"Ni": 2}, {"Si": 2}, "PROVIDE AND RECIEVE"], "ESTJ": [0, {}, {}, "NOTHING"], "ESTP": [2.4, {"Ni": 2, "Ti": 4}, {"Fi": 4, "Si": 2}, "PROVIDE AND RECIEVE"]},
"ETC": {"ETC"}
}
"""
// Moshi Adapter Code
private val moshi = Moshi.Builder().build()
private val mbtiTypesDataAdapter: JsonAdapter<MBTITypesData> = moshi.adapter(MBTITypesData::class.java)
private lateinit var allData: MBTITypesData
// MBTI type currently being loaded, for which data is displayed on the screen
// It is loaded with INFJ by default, as a matter of arbitrary selection
private var actualDisplayType = "INFJ";
// Sides of the Mind currently loaded, for which data is displayed on the screen
// It is loaded with Ego-Ego by default, as a matter of arbitrary selection
private var actualDisplayEgoShadowSubconciousSuperego = "Ego-Ego";
// Declare a switch that allows us to vary the operating mode of the program
// In bestMode will be able to know which Side of the Mind is better to use for each personality
private var bestMode = false;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// GridView Config
// TODO: Revisar este orden
changeGridData(actualDisplayType, actualDisplayEgoShadowSubconciousSuperego, gridData)
populateGrid(gridData)
// MBTI Type Dropdown Config
val mbtiTypeDropdown: Spinner = findViewById(R.id.mbtiTypeSpinner)
mbtiTypeDropdown.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val value = parent?.getItemAtPosition(position).toString()
mbtiTypeDropdownChanged(value)
}
private fun mbtiTypeDropdownChanged(value: String) {
actualDisplayType = value
changeGridData(actualDisplayType, actualDisplayEgoShadowSubconciousSuperego, gridData)
}
}
// Sides of the Mind Dropdown Config
val sidesOfTheMindDropdown: Spinner = findViewById(R.id.sidesOfTheMindSpinner)
sidesOfTheMindDropdown.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val value = parent?.getItemAtPosition(position).toString()
sidesOfTheMindDropdownChanged(value)
}
private fun sidesOfTheMindDropdownChanged(value: String) {
actualDisplayEgoShadowSubconciousSuperego = value
changeGridData(actualDisplayType, actualDisplayEgoShadowSubconciousSuperego, gridData)
}
}
}
private fun populateGrid(gridData: GridData) {
// GridView Config
gridView = findViewById(R.id.my_grid_view_list)
arrayList = setDataList(gridData.percentageList,
gridData.provideFunctionOneList,
gridData.provideFunctionTwoList,
gridData.recieveFunctionOneList,
gridData.recieveFunctionTwoList,
gridData.provideFunctionOnePercentagesList,
gridData.provideFunctionTwoPercentagesList,
gridData.recieveFunctionOnePercentagesList,
gridData.recieveFunctionTwoPercentagesList)
mbtiTypesDataJsonAdapter = MBTITypesDataJsonAdapter(applicationContext, arrayList!!)
allData = mbtiTypesDataAdapter.fromJson(allDataJSON)!!
gridView?.adapter = mbtiTypesDataJsonAdapter
gridView?.onItemClickListener = this
}
private fun changeGridData(
actualDisplayType: String,
actualDisplayEgoShadowSubconciousSuperego: String,
gridData: GridData
) {
var newGridData: GridData? = null
when (actualDisplayType) {
"ENFJ" -> {
newGridData = ENFJGridData(allData, gridData).enfjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"INFJ" -> {
newGridData = INFJGridData(allData, gridData).infjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"INTJ" -> {
newGridData = INTJGridData(allData, gridData).intjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ENTJ" -> {
newGridData = ENTJGridData(allData, gridData).entjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ENFP" -> {
newGridData = ENFPGridData(allData, gridData).enfpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"INFP" -> {
newGridData = INFPGridData(allData, gridData).infpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"INTP" -> {
newGridData = INTPGridData(allData, gridData).intpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ENTP" -> {
newGridData = ENTPGridData(allData, gridData).entpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ESTJ" -> {
newGridData = ESTJGridData(allData, gridData).estjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ISTJ" -> {
newGridData = ISTJGridData(allData, gridData).istjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ISTP" -> {
newGridData = ISTPGridData(allData, gridData).istpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ESTP" -> {
newGridData = ESTPGridData(allData, gridData).estpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ESFJ" -> {
newGridData = ESFJGridData(allData, gridData).esfjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ISFJ" -> {
newGridData = ISFJGridData(allData, gridData).isfjChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ISFP" -> {
newGridData = ISFPGridData(allData, gridData).isfpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
"ESFP" -> {
newGridData = ESFPGridData(allData, gridData).esfpChangeGridData(actualDisplayEgoShadowSubconciousSuperego)
}
}
populateGrid(newGridData!!)
}
fun getRandomNumberBetweenZeroAndOne(): Boolean {
return (Math.random() * 2).toInt() == 1
}
private fun getRandomDrawable(mbtiType: String): Int {
return when (mbtiType) {
"ENFJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.enfj_h
} else {
R.drawable.enfj_m
}
}
"INFJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.infj_h
} else {
R.drawable.infj_m
}
}
"INTJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.intj_h
} else {
R.drawable.intj_m
}
}
"ENTJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.entj_h
} else {
R.drawable.entj_m
}
}
"ENFP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.enfp_h
} else {
R.drawable.enfp_m
}
}
"INFP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.infp_h
} else {
R.drawable.infp_m
}
}
"INTP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.intp_h
} else {
R.drawable.intp_m
}
}
"ENTP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.entp_h
} else {
R.drawable.entp_m
}
}
"ESTJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.estj_h
} else {
R.drawable.estj_m
}
}
"ISTJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.istj_h
} else {
R.drawable.istj_m
}
}
"ISTP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.istp_h
} else {
R.drawable.istp_m
}
}
"ESTP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.estp_h
} else {
R.drawable.estp_m
}
}
"ESFJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.esfj_h
} else {
R.drawable.esfj_m
}
}
"ISFJ" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.isfj_h
} else {
R.drawable.isfj_m
}
}
"ISFP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.isfp_h
} else {
R.drawable.isfp_m
}
}
"ESFP" -> {
if (getRandomNumberBetweenZeroAndOne()) {
R.drawable.esfp_h
} else {
R.drawable.esfp_m
}
}
else -> {
R.drawable.enfj_h
}
}
}
private fun setDataList(percentageList: List<Int>,
provideFunctionOneList: List<String>,
provideFunctionTwoList: List<String>,
recieveFunctionOneList: List<String>,
recieveFunctionTwoList: List<String>,
provideFunctionOnePercentageList: List<Int>,
provideFunctionTwoPercentageList: List<Int>,
recieveFunctionOnePercentageList: List<Int>,
recieveFunctionTwoPercentageList: List<Int>): ArrayList<MBTITypesDataItem> {
var arrayList: ArrayList<MBTITypesDataItem> = ArrayList()
for (i in 0..15) {
arrayList.add(
MBTITypesDataItem(getRandomDrawable(mbtiTypesList[i]), mbtiTypesList[i],
percentageList[i], provideFunctionOneList[i], provideFunctionTwoList[i],
recieveFunctionOneList[i], recieveFunctionTwoList[i],
provideFunctionOnePercentageList[i], provideFunctionTwoPercentageList[i],
recieveFunctionOnePercentageList[i], recieveFunctionTwoPercentageList[i]
)
)
}
return arrayList
}
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
var items: MBTITypesDataItem = arrayList!!.get(position)
Toast.makeText(applicationContext, items.name, Toast.LENGTH_LONG).show()
Log.d("Prueba", "Hemos seleccionado: " + items.name.toString())
}
}
Here is the MBTITypesData:
package com.sanz.mbtigrid.mbtidataclasses
import com.sanz.mbtigrid.mbtidataclasses.ENFJEgoEgo
import com.sanz.mbtigrid.mbtidataclasses.ENFJEgoSubconcious
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class MBTITypesData(
val ENFJ_ego_ego: ENFJEgoEgo,
val ENFJ_ego_shadow: ENFJEgoShadow,
val ENFJ_ego_subconcious: ENFJEgoSubconcious,
val ENFJ_ego_superego: ENFJEgoSuperEgo,
val ENFJ_shadow_ego: ENFJShadowEgo,
val ENFJ_shadow_shadow: ENFJShadowShadow,
val ENFJ_shadow_subconcious: ENFJShadowSubconcious,
val ENFJ_shadow_superego: ENFJShadowSuperEgo,
val ENFJ_subconcious_ego: ENFJSubconciousEgo,
val ENFJ_subconcious_shadow: ENFJSubconciousShadow,
val ENFJ_subconcious_subconcious: ENFJSubconciousSubconcious,
val ENFJ_subconcious_superego: ENFJSubconciousSuperEgo,
val ENFJ_superego_ego: ENFJSuperEgoEgo,
val ENFJ_superego_shadow: ENFJSuperEgoShadow,
val ENFJ_superego_subconcious: ENFJSuperEgoSubconcious,
val ENFJ_superego_superego: ENFJSuperEgoSuperEgo,
val ETC_ego_ego: ETCEgoEgo
)
Here is the MBTITypesDataJsonAdapter:
package com.sanz.mbtigrid.mbtidataclasses
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.sanz.mbtigrid.R
class MBTITypesDataJsonAdapter(var context: Context, var arrayList: ArrayList<MBTITypesDataItem>): BaseAdapter() {
override fun getItem(position: Int): Any {
return arrayList.get(position)
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
return arrayList.size
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var view: View = View.inflate(context, R.layout.card_view_item_grid, null)
var cardView: CardView = view.findViewById(R.id.cardView)
var icons: ImageView = view.findViewById(R.id.icons)
var names: TextView = view.findViewById(R.id.name_text_view)
var compatibilityPercentage: TextView = view.findViewById(R.id.compatibility_percentage)
var provideFunctionOne: TextView = view.findViewById(R.id.provide_function_1)
var provideFunctionTwo: TextView = view.findViewById(R.id.provide_function_2)
var recieveFunctionOne: TextView = view.findViewById(R.id.recieve_function_1)
var recieveFunctionTwo: TextView = view.findViewById(R.id.recieve_function_2)
var listItem: MBTITypesDataItem = arrayList.get(position)
icons.setImageResource(listItem.icons!!)
names.text = listItem.name
if (names.text[1] == 'N' && names.text[2] == 'F') {
cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.guardians))
} else if (names.text[1] == 'N' && names.text[2] == 'T') {
cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.intellectuals))
} else if (names.text[1] == 'S' && names.text[3] == 'J') {
cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.idealists))
} else if (names.text[1] == 'S' && names.text[3] == 'P') {
cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.artisans))
}
var percentage: String = listItem.compatibilityPercentage.toString() + "%"
compatibilityPercentage.text = percentage
if (listItem.provideFunctionOneName != null) {
if (!listItem.provideFunctionOneName!!.equals("")) {
provideFunctionOne.isVisible = true
provideFunctionOne.text = listItem.provideFunctionOneName!!
provideFunctionOne.alpha = listItem.provideFunctionOnePercentage!!.toFloat() / 100
} else {
provideFunctionOne.isVisible = false
}
} else {
provideFunctionOne.isVisible = false
}
if (listItem.provideFunctionTwoName != null) {
if (!listItem.provideFunctionTwoName!!.equals("")) {
provideFunctionTwo.isVisible = true
provideFunctionTwo.text = listItem.provideFunctionTwoName!!
provideFunctionTwo.alpha = listItem.provideFunctionTwoPercentage!!.toFloat() / 100
} else {
provideFunctionTwo.isVisible = false
}
} else {
provideFunctionTwo.isVisible = false
}
if (listItem.recieveFunctionOneName != null) {
if (!listItem.recieveFunctionOneName!!.equals("")) {
recieveFunctionOne.isVisible = true
recieveFunctionOne.text = listItem.recieveFunctionOneName!!
recieveFunctionOne.alpha = listItem.recieveFunctionOnePercentage!!.toFloat() / 100
} else {
recieveFunctionOne.isVisible = false
}
} else {
recieveFunctionOne.isVisible = false
}
if (listItem.recieveFunctionTwoName != null) {
if (!listItem.recieveFunctionTwoName!!.equals("")) {
recieveFunctionTwo.isVisible = true
recieveFunctionTwo.text = listItem.recieveFunctionTwoName!!
recieveFunctionTwo.alpha = listItem.recieveFunctionTwoPercentage!!.toFloat() / 100
} else {
recieveFunctionTwo.isVisible = false
}
} else {
recieveFunctionTwo.isVisible = false
}
return view
}
}
Here is my build.gradle (Module):
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.sanz.mbtigrid"
minSdk 29
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Dependency for Material Components
implementation 'com.google.android.material:material:1.6.1'
// Moshi (JSON)
implementation "com.squareup.moshi:moshi:1.14.0"
implementation "com.squareup.moshi:moshi-kotlin:1.14.0"
annotationProcessor 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
}
How can I solve this problem?
Thank you very much in advance