Please i have been trying this for weeks now. I have a fragment that displays notifications. But it time i click on the notification my app crashes. it points me the line below Picasso.get().load(user!!.getImage()).placeholder(R.drawable.profile).into(imageView)
and it says: java.lang.IllegalArgumentException: Path must not be empty
From logcat, using picasso seems to be the problem but i am new to programming and i have no idea what exacty to do. Please help me. Thank you
Below is the complete code for my notificationAdapter
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(mContext).inflate(R.layout.notifications_item_layout , parent,false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val notification = mNotification[position]
if(notification.getText().equals("Admirers you")){
holder.text.text = "Admirers you"
}
else if(notification.getText().equals("Liked your post")){
holder.text.text = "Liked your post"
}
else if (notification.getText().contains("commented:")){
holder.text.text = notification.getText().replace("commented:", "commented: ")
}
else{
holder.text.text = notification.getText()
}
userInfo(holder.profileImage, holder.fullname, notification.getUserId())
if(notification.isIsPost()){
holder.postImage.visibility = View.VISIBLE
getPostImage(holder.postImage, notification.getPostId())
}
else{
holder.postImage.visibility = View.GONE
}
holder.itemView.setOnClickListener {
if(notification.isIsPost()){
val editor = mContext.getSharedPreferences("PREFS", Context.MODE_PRIVATE).edit()
editor.putString("postId", notification.getPostId())
editor.apply()
(mContext as FragmentActivity).getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, PostDetailsFragment()).commit()
}
else{
val editor = mContext.getSharedPreferences("PREFS", Context.MODE_PRIVATE).edit()
editor.putString("profileId", notification.getUserId())
editor.apply()
(mContext as FragmentActivity).getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, ProfileFragment()).commit()
}
}
}
override fun getItemCount(): Int {
return mNotification.size
}
inner class ViewHolder(@NonNull itemView: View) : RecyclerView.ViewHolder(itemView)
{
var postImage: ImageView
var profileImage : CircleImageView
var fullname : TextView
var text : TextView
init {
postImage = itemView.findViewById(R.id.notification_post_image)
profileImage = itemView.findViewById(R.id.notifications_profile_image)
fullname = itemView.findViewById(R.id.fullname_notification)
text = itemView.findViewById(R.id.comment_notification)
}
}
private fun userInfo(imageView: ImageView, fullname: TextView, publisherId:String)
{
val usersRef =
FirebaseDatabase.getInstance().reference
.child("Users")
.child(publisherId)
usersRef.addValueEventListener(object : ValueEventListener
{
override fun onDataChange(p0: DataSnapshot)
{
if (p0.exists())
{
val user = p0.getValue(User::class.java)
Picasso.get().load(user!!.getImage()).placeholder(R.drawable.profile).into(imageView)
fullname.text = user.getfullname()
}
}
override fun onCancelled(p0: DatabaseError) {
}
})
}
private fun getPostImage(imageView: ImageView, postID:String)
{
val postRef =
FirebaseDatabase.getInstance()
.reference.child("Posts")
.child(postID)
postRef.addValueEventListener(object : ValueEventListener
{
override fun onDataChange(p0: DataSnapshot)
{
if (p0.exists()) {
val post = p0.getValue<Post>(Post::class.java)
Picasso.get().load(post!!.getpostimage()).placeholder(R.drawable.profile)
.into(imageView)
}
}
override fun onCancelled(p0: DatabaseError) {
}
})
}
}
And also my notification fragment
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="Fragments.NotificationsFragment">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/app_bar_layout_notifications"
android:background="@color/white">
<androidx.appcompat.widget.Toolbar
android:id="@+id/notifications_toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:background="@android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notifications"
android:textSize="18sp"
android:maxLines="1"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_centerVertical="true"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_notifications"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_below="@+id/app_bar_layout_notifications">
</androidx.recyclerview.widget.RecyclerView>
Then in case you need more info, here's my notifications item layout. Thank you
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/notifications_profile_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/profile">
</de.hdodenhof.circleimageview.CircleImageView>
<LinearLayout
android:layout_toEndOf="@+id/notifications_profile_image"
android:layout_toStartOf="@+id/notification_post_image"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/fullname_notification"
android:textStyle="bold"
android:textColor="@color/teal_200"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="@+id/comment_notification"
android:textStyle="bold"
android:textColor="@color/teal_200"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<ImageView
android:id="@+id/notification_post_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true">
</ImageView>