Ich arbeite an einer Einkaufs-App und habe ein Fragment zum Hinzufügen von Produkten zur Produktliste erstellt.
Ich muss eine externe Speicherberechtigung lesen, um ein Foto zu Produkten hinzuzufügen, also versuche ich, registerForActivityResult() in meinem Fragment zu verwenden, erhalte aber eine Fehlermeldung.
Ich bin neu in der Android-Programmierung und weiß daher nicht, ob ich sie richtig verwende.
Ich habe jede Antwort aus anderen Fragen ausprobiert Ich habe es gefunden, aber sie haben nicht funktioniert.
Fehlermeldung:
IllegalStateException: Fragment AddActivity after being created. Fragments must call rHgS5orgPvsuzJ7shn8vw28y1XaePY4uDP() before they are created (i.e. initialization, onAttach(), or onCreate()).
at androidx.fragment.app.Fragment.prepareCallInternal(Fragment.java:3482)
at androidx.fragment.app.Fragment.rHgS5orgPvsuzJ7shn8vw28y1XaePY4uDP(Fragment.java:3449)
at com.example.TheDentalSupplies.AddActivity.showImageChooser(AddActivity.kt:120)
at com.example.TheDentalSupplies.AddActivity.requestPermission(AddActivity.kt:96)
at com.example.TheDentalSupplies.AddActivity.onViewCreated$lambda-1(AddActivity.kt:66)
at com.example.TheDentalSupplies.AddActivity.lambda$gx8TAUa5Jk3WDkvGOWG0oB39kiM(Unknown Source:0)
at com.example.TheDentalSupplies.-$$Lambda$AddActivity$gx8TAUa5Jk3WDkvGOWG0oB39kiM.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
Ich arbeite an einer Einkaufs-App und habe ein Fragment zum Hinzufügen von Produkten zur Produktliste erstellt. Ich muss eine externe Speicherberechtigung lesen, um ein Foto zu Produkten hinzuzufügen, also versuche ich, registerForActivityResult() in meinem Fragment zu verwenden, erhalte aber eine Fehlermeldung. Ich bin neu in der Android-Programmierung und weiß daher nicht, ob ich sie richtig verwende. Ich habe jede Antwort aus anderen Fragen ausprobiert Ich habe es gefunden, aber sie haben nicht funktioniert. Fehlermeldung: [code]IllegalStateException: Fragment AddActivity after being created. Fragments must call rHgS5orgPvsuzJ7shn8vw28y1XaePY4uDP() before they are created (i.e. initialization, onAttach(), or onCreate()). at androidx.fragment.app.Fragment.prepareCallInternal(Fragment.java:3482) at androidx.fragment.app.Fragment.rHgS5orgPvsuzJ7shn8vw28y1XaePY4uDP(Fragment.java:3449) at com.example.TheDentalSupplies.AddActivity.showImageChooser(AddActivity.kt:120) at com.example.TheDentalSupplies.AddActivity.requestPermission(AddActivity.kt:96) at com.example.TheDentalSupplies.AddActivity.onViewCreated$lambda-1(AddActivity.kt:66) at com.example.TheDentalSupplies.AddActivity.lambda$gx8TAUa5Jk3WDkvGOWG0oB39kiM(Unknown Source:0) at com.example.TheDentalSupplies.-$$Lambda$AddActivity$gx8TAUa5Jk3WDkvGOWG0oB39kiM.onClick(Unknown Source:4) at android.view.View.performClick(View.java:7125) at android.view.View.performClickInternal(View.java:7102) [/code] AddActivity.kt: [code]class AddActivity : Fragment() { private lateinit var img:ImageView private lateinit var requestLauncher: ActivityResultLauncher
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val image1 = view.findViewById(R.id.addImage1) val image2 = view.findViewById(R.id.addImage2) val image3 = view.findViewById(R.id.addImage3) val image4 = view.findViewById(R.id.addImage4) val image5 = view.findViewById(R.id.addImage5)
fun showImageChooser(imageView: ImageView) { val galleryIntent = Intent( Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI )
val launchSomeActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> if (result.resultCode == Activity.RESULT_OK) { val data: Intent? = result.data if (data != null){ try { val mSelectedImageFileUri = data.data!!
private fun addItem(view: View) { //val image1 = view.findViewById(R.id.addImage1) val addProductName = view.findViewById(R.id.addTitleEditText).text.toString() val addProductDesc = view.findViewById(R.id.addDescEditText).text.toString() val addProductPrice = view.findViewById(R.id.addPrice).text.toString() val addProductCat = view.findViewById(R.id.selectCategoryEt).text.toString()
when{ TextUtils.isEmpty(addProductName.trim { it Toast.makeText(activity, "Please Enter Product Name.", Toast.LENGTH_SHORT).show()
TextUtils.isEmpty(addProductDesc.trim { it Toast.makeText(activity, "Please Enter Product Description.", Toast.LENGTH_SHORT).show()
TextUtils.isEmpty(addProductCat.trim { it Toast.makeText(activity, "Please Select Product Category.", Toast.LENGTH_SHORT).show()
TextUtils.isEmpty(addProductPrice.trim { it Toast.makeText(activity, "Please Enter Product Price.", Toast.LENGTH_SHORT).show()
else -> { //val index = 0 val firebaseUser: String = Firebase.auth.currentUser!!.uid val product = ProductItem(R.drawable.add_box, addProductName, 0.0, "Serhat Yilmaz", addProductPrice.toInt(), addProductDesc, addProductCat.toInt(), firebaseUser)
Ich arbeite an einer Shopping-App und habe ein Fragment zum Hinzufügen von Produkten zur Produktliste erstellt. Ich benötige eine Leseberechtigung für den externen Speicher, um ein Foto zum Produkt...
Nicht erfasste mysqli_sql_Exception: Sie haben einen Fehler in Ihrer SQL-Syntax; Überprüfen Sie das Handbuch, das Ihrer MariaDB-Serverversion entspricht, auf...
Ich versuche, eine neue Kampagne für meine erste App zu starten, aber ich bekomme immer wieder die folgende Warnung:
None of your ads are running. Your campaigns and ad groups are paused or removed....
Als Titeldetail Elemente.
Eine normale Implementierung wurde durchgeführt, z. B. Aktivität A startet einen Aktivitätslauncher über eine Schaltfläche Klick. Der Aktivitätslauncher ist außerhalb aller...