0

I can't cast this please help, It is the same class name with android view.View and com.stfalcon, but I can't change the class name to any of those because it is READ_ONLY_file, how can I cast this? I need to cast this >>>>> this.messagesList = (MessagesList) findViewById(R.id.messagesList);

this is my dependency, and I already import it from my DefaultMessagesActivity.java

implementation 'com.github.stfalcon:chatkit:0.3.3'

This is my Java

public class DefaultMessagesActivity extends DemoMessagesActivity
    implements MessageInput.InputListener,
    MessageInput.AttachmentsListener,
    MessageInput.TypingListener{

public DefaultMessagesActivity(MessagesList messagesList){

}

public static void open(Context context) {
    context.startActivity(new Intent(context, DefaultMessagesActivity.class));
}
private MessagesList messagesList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_default_messages);

    this.messagesList = (MessagesList) findViewById(R.id.messagesList); //ERROR HERE CANT CAST

This is my xml file name activity_default_messages.xml

    <com.stfalcon.chatkit.messages.MessagesList
    android:id="@+id/messagesList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/input"/>

    
Kneelon
  • 239
  • 3
  • 12

1 Answers1

2

You are doing similar error like you did here. same class name with android view.View and com.stfalcon doesn't mean the classes are same because they have same name.

com.stfalcon.chatkit.messages.MessagesList messagesList = findViewById(R.id.messagesList);

that will be the correct statement. When you use implementation 'com.github.stfalcon:chatkit:0.3.3' and use a library you will get all the classes you can use into your project but you can not modify or convert those classes. If there is a special need to modify the response from one of library class then either use interfaces or create a custom class by extending library class.

Happy Coding !

Nikhil Sharma
  • 897
  • 1
  • 4
  • 18