Essentially all I want to do is put each array element on a new line but when using the join() method I get the error, Cannot resolve method 'join' in 'String'.
public class revision_testing extends AppCompatActivity {
start_timetable start_timetable = new start_timetable();
revision_time revision_time = new revision_time();
public int append_counter = 0;
public int revision_days = 25; //FOR TEST
String[] all_dates = new String[revision_days];
String date=start_timetable.clicked_date;
public int day=start_timetable.day;
public int month=start_timetable.month;
public int year=start_timetable.year;
int [] days_in_months = {31,28,31,30,31,30,31,31,30,31,30,31};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_revision_testing);
getSupportActionBar().hide();
for(int i=revision_days;i>0;i--){
if (day >0){
all_dates[append_counter] = year+"/"+month+"/"+day;
day--;
append_counter++;
}else {
day=days_in_months[month];
month++;
all_dates[append_counter] = year+"/"+month+"/"+day;
day--;
append_counter++;
}
}
all_dates= all_dates.join("\n",all_dates); //This line is the issue
}
Most likely you wanted to use the String.join method instead of all_dates.join:
String allDatesJoined = String.join("\n", all_dates);
You are also assigning the result back into the all_dates array. You need to tell Java which position in the array you want to use. If you want to assign to the first array position, use all_dates[0]:
all_dates[0] = allDatesJoined;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With