简体   繁体   English

我有问题,为什么我不能运行 Picasso.get().load(users.getProfile()).into(R.id.profile_image); 什么问题?

[英]I have problem, Why i can't run Picasso.get().load(users.getProfile()).into(R.id.profile_image); whats problem?

I have a problem.我有个问题。 I will try to run this program.我会尝试运行这个程序。 But I can't do that.但我不能那样做。 I see remark in Picasso.get().load(users.getProfile()).into(R.id.profile_image);我在 Picasso.get().load(users.getProfile()).into(R.id.profile_image); 中看到了评论I see the remark in.into.我在.into 中看到了这句话。

ANd, I just want to run a picture from firebase.而且,我只想从 firebase 运行一张图片。 Please check it.请检查一下。 And Help me.并帮助我。

Here's MainActivit.kt Code:这是 MainActivit.kt 代码:


class MainActivity : AppCompatActivity() {



    var refUsers: DatabaseReference? = null
    var firebaseUser: FirebaseUser? = null

    /**
     * Need Dependencys
     * implementation 'com.google.firebase:firebase-core:18.0.2'
    implementation 'com.google.firebase:firebase-auth:20.0.3'
    implementation 'com.google.firebase:firebase-storage-ktx:19.2.1'
    implementation 'com.google.firebase:firebase-database-ktx:19.6.0'
    implementation 'com.google.firebase:firebase-messaging:21.0.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
     */



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(findViewById(R.id.toolbar_main)) // eikhane uporer action bar design ta call kora hoece

        firebaseUser = FirebaseAuth.getInstance().currentUser
        refUsers = FirebaseDatabase.getInstance().reference.child("Users").child(firebaseUser!!.uid)





        val toolbar: androidx.appcompat.widget.Toolbar = findViewById(R.id.toolbar_main)
        setSupportActionBar(toolbar)
        supportActionBar!!.title = "" // jodi ami amar apps er default name show koraite chai toolbar e tahole eikhane sei name ta ami dite pari.





        val tablayout: TabLayout = findViewById(R.id.tab_layout)
        val viewPager: ViewPager = findViewById(R.id.view_pager) // eikhane viewpager bolte ek tab theke arek tab slide kore jawar jonnoi eti bebohar kora hoy
        val viewPagerAdapter = ViewPagerAdapter(supportFragmentManager)


        /**
         * eikhane viewpager.Adapter die CHATfragment, searchfragment,settingfragment ke add kora hoece.
         */
        viewPagerAdapter.addFragment(ChatsFragment(),"Chats")
        viewPagerAdapter.addFragment(SettingsFragment(),"Search")
        viewPagerAdapter.addFragment(SettingsFragment(),"Settings")

        viewPager.adapter = viewPagerAdapter //eikhane ViewpagerAdapter er sathe viewpager ke jog kora hoice.
        tablayout.setupWithViewPager(viewPager) //eikhane Tablayout er sathe viewpager ke jog kora hoice.


        //display username and profile picture
        refUsers!!.addValueEventListener(object : ValueEventListener {
            override fun onDataChange(snapshot: DataSnapshot) {
                if (snapshot.exists())
                {

                    val users: Users? = snapshot.getValue(Users::class.java)

                    findViewById<TextView>(R.id.user_name).text = users!!.getUsername()
                    Picasso.get().load(users.getProfile()).into(R.id.profile_image);

                }


            }

            override fun onCancelled(error: DatabaseError) {
                TODO("Not yet implemented")
            }
        })




    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.menu_main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.action_logout -> {
                FirebaseAuth.getInstance().signOut()

                val intent = Intent(this@MainActivity, WelcomeActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
                startActivity(intent)
                finish()
                return true
            }
        }

        return false

    }

    internal class ViewPagerAdapter(fragmentManager: FragmentManager) :
        FragmentPagerAdapter(fragmentManager)
    {

        private val fragments: ArrayList<Fragment>
        private val titles: ArrayList<String>


        init {
            fragments = ArrayList<Fragment>()
            titles = ArrayList<String>()
        }


        override fun getCount(): Int {
            return fragments.size
        }

        override fun getItem(position: Int): Fragment {
            return fragments[position]
        }

        fun addFragment(fragment: Fragment, title: String)
        {
            fragments.add(fragment)
            titles.add(title)

        }


        override fun getPageTitle(i: Int): CharSequence? {
            return titles[i]
        }
    }

}


Here is Users.kt Code:这是 Users.kt 代码:


class Users

{
    private var uid: String =""
    private var username: String =""
    private var profile: String =""
    private var cover: String =""
    private var status: String =""
    private var search: String =""
    private var facebook: String =""
    private var instagram: String =""
    private var website: String =""


    constructor()
    constructor(
            uid: String,
            username: String,
            profile: String,
            cover: String,
            status: String,
            search: String,
            facebook: String,
            instagram: String,
            website: String)
    {
        this.uid = uid
        this.username = username
        this.profile = profile
        this.cover = cover
        this.status = status
        this.search = search
        this.facebook = facebook
        this.instagram = instagram
        this.website = website
    }

    fun getUID(): String?{
        return uid
    }

    fun setUID(uid: String){
        this.uid = uid
    }


    /**
     *
     *
     */


    fun getUsername(): String?{
        return username
    }

    fun setUsername(username: String){
        this.username = username
    }


    /**
     *
     */




    fun getStatus(): String?{
        return status
    }

    fun setStatus(status: String){
        this.status = status
    }

    /**
     *
     */




    fun getProfile(): String?{
        return profile
    }

    fun setProfile(status: String){
        this.profile = profile
    }

    /**
     *
     */





    fun getCover(): String?{
        return cover
    }

    fun setCover(cover: String){
        this.cover = cover
    }







    fun getSearch(): String?{
        return search
    }

    fun setSearch(search: String){
        this.search = search
    }







    fun getFacebook(): String?{
        return facebook
    }

    fun setFacebook(facebook: String){
        this.facebook = facebook
    }







    fun getInstagram(): String?{
        return instagram
    }

    fun setInstagram(instagram: String){
        this.instagram = instagram
    }







    fun getWebsite(): String?{
        return website
    }

    fun setWebsite(website: String){
        this.website = website
    }



}

Delete this line:删除这一行:

Picasso.get().load(users.getProfile()).into(R.id.profile_image);

And replace with:并替换为:

Picasso.get().load(users.getProfile()).into(findViewById<ImageView>(R.id.profile_image));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法在“ SettingActivity”中获取个人资料图片? - Why i can't get profile image in 'SettingActivity'? 为什么我无法运行 Vue 项目,在 app.scss 中有问题? - Why I can't run a Vue project with a problem in app.scss? 如何在毕加索的帮助下获取存储在Firebase数据库中的图像 - How can I get the image that stored in Firebase Database with the help of Picasso 我能在firebase android中加载另一个用户个人资料图片吗? - Am I able to load another users profile image in firebase android? Picasso无法在StorageReference的onSuccess方法中加载图像 - Picasso can't load image inside StorageReference's onSuccess method 尝试使用 firebase 运行我的 Android 应用程序时遇到问题 - I have a problem when trying to run my Android application with firebase 如何解决 FIREBASE UNIQUE ID 问题 - How can I solve FIREBASE UNIQUE ID problem 您好,我在将图片上传到 Firebase 存储时遇到问题 - Hello, I have problem to upload my image to my firebase storage 我的 firebase 连接有问题 - i have a problem with firebase connecting 您好,亲爱的,我将我的应用程序附加到 firbase adabase,所以它崩溃了。 我已经尝试了太多来解决这个问题,但无法摆脱请帮助我 - Hello Dear, I attach my app with firbase adabase so it crashes. I have tried too much to sort out of this Problem but can't get rid of please help me
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM