Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanted to write a program that uses the join method, but the compiler got an error.

What's the problem?


Error:
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .


What I have tried:

package package1;

public class MainClass {

	public static void main(String[] args) {
		
		
		String[] strArray = { "How", "To", "Do", "In", "Java" };
        
		String joinedString = String.join(", ", strArray);
		 
		System.out.println(joinedString);
		

	}

}
Posted
Updated 3-Sep-21 22:48pm
Comments
Richard MacCutchan 4-Sep-21 4:31am    
I just tried that code and it compiles and runs fine.
Richard MacCutchan 4-Sep-21 7:28am    
Just to be certain, I installed Java 1.8 and tried again and it worked fine. There must be something else about your system that you are not telling us. Please try again and provide all complete error messages as displayed on your system (ensure you use copy and paste). Also if you have any other modules in package1, then provide those details also.

1 solution

At a guess - and that's all it can be since we have no access to your computer - it's something to do with package1 rather than the code you show.

If I use an online Java IDE, you code will not compile with this line in:
package package1;
This is to be expected, since I don;t have the package it refers to.
Remove the line, the code runs fine and I get exactly what I expected:
How, To, Do, In, Java


So remove the line yourself, and see if it works. When it does, start looking at the package to see what's wrong with that!

Sorry, but we can't do that for you!
 
Share this answer
 
Comments
Richard MacCutchan 4-Sep-21 4:57am    
I did it with package1 and it still works fine.
OriginalGriff 4-Sep-21 5:01am    
I guess it depends what's in the package ... :D
Richard MacCutchan 4-Sep-21 5:33am    
Nothing as far as I can see, but as usual the error report is not clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900