Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Passing Firestore Data Through RecyclerView to Activity

Posted on November 11, 2022 By

Solution 1 :

Because you are not sending “category” as a object of Category().
Instead you are sending it’s category field, i assume it’s string.

//intent.putExtra("category", category[position].category)

intent.putExtra("category", category[position]) // use this

Problem :

I’m trying to pass populated data that I’m getting through Firestore, when I press on a position on a recyclerview, onto another activity. However, I’m getting an error when I try to press on a recyclerview item. Is it because I’m passing intent.getParcelableExtra()!! and I need to pass something else? Thank you!

This is the error:

Caused by: java.lang.NullPointerException
at com.zwdalpha.skedaddle.Activities.Services.CategoryServiceActivity.onCreate(CategoryServiceActivity.kt:32)

PopularCategoriesAdapter.kt

class PopularCategoriesAdapter(val category: ArrayList<Category>) :
    RecyclerView.Adapter<PopularCategoriesAdapter.ViewHolder>() {

    var selectedCategory = Category("", "")

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bindCategory(category[position])

        holder.itemView.setOnClickListener { v ->
            selectedCategory.category = category[position].category
            val intent = Intent(holder.itemView.context, CategoryServiceActivity::class.java)
            intent.putExtra("category", category[position].category)
            holder.itemView.context.startActivity(intent)
        }
    }
}

CategoryServiceActivity.kt

class CategoryServiceActivity : AppCompatActivity() {

    lateinit var category: Category

    @SuppressLint("NotifyDataSetChanged")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_category_service)

// Line 32 - category = intent.getParcelableExtra("category")!!
    }
}

I tried switching the intent.getParcelableExtra("category")!! out with intent.extras!!.get("category") as Category but still getting the error.

Comments

Comment posted by Alex Mamo

“I’m getting an error” doesn’t provide enough information so we can help. What exactly doesn’t work? What are the exact errors?

Comment posted by Zachary Smouse

I put the error message that I’m getting from the Logcat. I’m getting a NullPointException when I try going to the CategoryServiceActivity

READ  [FIXED] java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.clear()' on a null object reference
Powered by Inline Related Posts
Android Tags:android, android-recyclerview, google-cloud-firestore, kotlin

Post navigation

Previous Post: [FIXED] java – is permission needed when choosing image from gallery on android?
Next Post: [FIXED] Android Java: How to get component in a custom view? (Trying to access components via findByViewId and get null)

Related Posts

[FIXED] java – How to get JSON data by POST method with Secret code in android studio Android
[FIXED] Android Manifest – Facebook Common Android
[FIXED] Android save data to firebase Database Android
[FIXED] java – MediaCodec AV Sync when decoding Android
[FIXED] java – How to update user data without changes into Firestore when it’s checking for already existence in database? Android
[FIXED] database – DB open fails error in Android and could be due to the DB file location Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme