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

Really Weird.  Came across this error in Chapter 24 of the Basic Java Programming Course in Udemy.  When I first used the below code, it compiled fine.  Later, I added printf as part of learning string formatting. As Eclipse started complaining, I changed the compiler settings to 1.6, and from then the StringBuilder code just doesn’t work.

So, what I figured out  – Eclipse with version 1.6 cannot support StringBuilder class and system.out.printf() simultaneously. Here is the code I used .  I first compiled and ran StringBuilder class, and then commented out to further practice printf function.

There are a bunch of solutions suggested for this –  Close & re-open project,  add JRE to build path again, Clean the Java Project and so on. Give all these a try, but if nothing works – check if 2 parts of code are incompatible  together with the compiler. You can test things by commenting one portion and running Java program again.

public class StringBuffer {
public static void main(String[] args) {

/* StringBuilder b = new StringBuilder();
b.append(“alpha”);

System.out.println(b.toString()); */

// String Formatting

System.out.printf(“Total cost – %d, Total Quantity – %d\n”, 120,5);

for(int i = 0;i < 20; i++){
System.out.printf(“%d – %s\n”, i, “here is some text”);
}

// Formatting floating point values

System.out.printf(“Total value = %.2f”, 5.6897);
System.out.printf(“Total value = %-5.1f”, 56897.3446);

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s