0

I am trying to add the data of textview into array. myLogClass is a array list and The codes is as follows:

    String txt_datetime = txt_date.getText().toString();; 
    String txt_messageData = txt_message.getText().toString();
    String txt_day = this.dayName;



    List< myLogClass > results = null;
    results = new ArrayList< myLogClass >();

    results.add( new myLogClass( txt_datetime, txt_messageData, txt_day ) );

I have setter and getter method in myLogClass and has constructor with 3 variable which is as follows:

public diaryLogs(int dateTime, String messagetxt, String dayN){

    setDayCode(dateTime);
    setDateTime(messagetxt);
    setDairyText(dayN);

}//end constructor.

While i tried to add method it says the constructor is undefined.

Thanks for your help in advance

usrNotFound
  • 2,680
  • 3
  • 25
  • 41

2 Answers2

0

To be able to add a diaryLogs instance to the result array, the ArrayList should be of diaryLogs. Here I made the modification before going to the other issue.

The definition of the diaryLogs constructor is (int dateTime, String messagetxt, String dayN), that being said, that function is expecting an int, and then two strings as parameters.

To get this working you need to convert the string txt_datetime to int before passing it to the constructor.

String txt_datetime = txt_date.getText().toString();; 
String txt_messageData = txt_message.getText().toString();
String txt_day = this.dayName;

// Convert to Integer
int txt_datetime_int = Integer.parseInt(txt_datetime);

// Define the ArrayList as diaryLogs
List< diaryLogs > results = null;
results = new ArrayList< diaryLogs >();

// Pass as Integer
results.add( new diaryLogs( txt_datetime_int , txt_messageData, txt_day )
BenMorel
  • 34,448
  • 50
  • 182
  • 322
gpopoteur
  • 1,509
  • 10
  • 18
0

In this line:

results.add( new diaryLogs( txt_datetime, txt_messageData, txt_day ) );

txt_datetime is a String while Integer is expected. This is why you get this message.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216