Я писал код для своего мобильного приложения.
Мое приложение написано на Kotlin вместо Java, но если было сказано, то я тоже буду декомпилировать Java.
Мой главный мотив в настоящее время - добавить в мое приложение параметр просмотра зависимого списка с помощью параметра Spinner и привязки данных. Итак, я создал несколько счетчиков в моем activity_order. xml.
Это мой activity_order. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Order">
<ImageView
android:id="@+id/imageView"
android:layout_width="138dp"
android:layout_height="96dp"
android:layout_marginEnd="280dp"
android:layout_marginRight="280dp"
android:layout_marginBottom="632dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/logo_cut" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="136dp"
android:text="DISTRICT NAME :"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.059"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="LIQUOR TYPE :"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.054"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:text="SHOP NAME :"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.053"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="LIQUOR BRAND :"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.058"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QUANTITY :"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:layout_constraintVertical_bias="0.193" />
<Spinner
android:id="@+id/spinner_district"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.192" />
<Spinner
android:id="@+id/spinner_type"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.623"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.309" />
<Spinner
android:id="@+id/spinner_shop"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.653"
app:layout_constraintStart_toEndOf="@+id/textView4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.425" />
<Spinner
android:id="@+id/spinner_brand"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.545"
app:layout_constraintStart_toEndOf="@+id/textView5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.541" />
<!--
<Spinner
android:id="@+id/spinner_quantity"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.698"
app:layout_constraintStart_toEndOf="@+id/textView6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.66" />
-->
<Spinner
android:id="@+id/spinner_quantity"
android:layout_width="166dp"
android:layout_height="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.698"
app:layout_constraintStart_toEndOf="@+id/textView6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.66" />
<Button
android:id="@+id/btn1"
android:layout_width="302dp"
android:layout_height="34dp"
android:layout_marginBottom="112dp"
android:background="@drawable/custom_btn_proceed"
android:text="PROCEED TO PAYMENT"
android:textColor="#FFFFFF"
android:textColorHint="#F44336"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:layout_constraintVertical_bias="0.315" />
</androidx.constraintlayout.widget.ConstraintLayout>
В этом упражнении я хотел сначала создать зависимый список с идентификатором прядильщика spinner_district , а все остальные зависят от верхнего прядильщика.
Поэтому я сначала добавил следующий код в свой файл Gradle
viewBinding
{
enabled=true
}
, а затем начал создавать команду привязки для списка в моем Kotlin файле следующим образом:
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val arrayList_District= arrayListOf<String>("Hapur","Meerut","Noida")
val arrayAdapter_District=ArrayAdapter(applicationContext,R.layout.list_district,arrayList_District)
binding.spParent.adapter=arrayAdapter_District
Это мой полный kotlin файл для activity_order. xml с именем Order.kt
package com.example.e_dukan
import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import com.example.e_dukan.databinding.ActivityMainBinding
class Order : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_order)
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// Binding Command for Dependent Spinner/////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val arrayList_District= arrayListOf<String>("Hapur","Meerut","Noida")
val arrayAdapter_District=ArrayAdapter(applicationContext,R.layout.list_district,arrayList_District)
binding.spParent.adapter=arrayAdapter_District
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Spinner_district View Command///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
val spinner: Spinner = findViewById(R.id.spinner_district)
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter.createFromResource(
this,
R.array.spinner_district,
android.R.layout.simple_spinner_item
).also { adapter ->
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// Apply the adapter to the spinner
spinner.adapter = adapter
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
/*
class Order : Activity(), AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
val spinner: Spinner = findViewById(R.id.spinner_district)
spinner.onItemSelectedListener = this
}
override fun onNothingSelected(parent: AdapterView<*>) {
// Another interface callback
}
}
*/
Но когда я собираю градиент, он показывает следующую ошибку:
Executing tasks: [:app:assembleDebug] in project A:\E Dukan
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:dataBindingMergeDependencyArtifactsDebug UP-TO-DATE
> Task :app:dataBindingMergeGenClassesDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders UP-TO-DATE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugResources
> Task :app:dataBindingGenBaseClassesDebug
> Task :app:processDebugResources
> Task :app:compileDebugKotlin FAILED
e: A:\E Dukan\app\src\main\java\com\example\e_dukan\Order.kt: (11, 40): Unresolved reference: ActivityMainBinding
e: A:\E Dukan\app\src\main\java\com\example\e_dukan\Order.kt: (23, 23): Unresolved reference: ActivityMainBinding
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
15 actionable tasks: 4 executed, 11 up-to-date
Пожалуйста, помогите мне решить эту проблему сборки gradle.