This article mainly introduces the relevant information on how to solve the error xxx cannot be resolved to a type in java eclipse. Friends who need it can refer to it
xxx cannot be resolved to a type
Introduction Newly imported projects in eclipse often see the error message "XX cannot be resolved to a type". This article will give a brief summary.
Text
(1) jdk does not match (or does not exist)
Project specification The jdk is "jdk1.6.0_18", and the current eclipse uses "jdk1.6.0_22". Need to make simple adjustments in BuildPath | Libraries.
(2) Jar package is missing or conflicting
When the jar package where "XX" is located cannot be found, this error will be reported. To solve the problem, you only need to find (ctrl+click, you may be able to see the name of the jar package) the corresponding jar package import project.
In addition, this error will also be reported when the same XX appears. It may be necessary to adjust, unpack, and select and delete packages.
(3) Caused by eclipse’s project type search strategy
Under eclipse, the above two items have been compared, and there are no problems. This error happened to be reported. At this time, you need to operate Project | Clean... and the problem will be solved. The reason is due to the mechanism. For some special reasons, eclipse failed to automatically compile the source code to build/classes (or other classes directory), resulting in the type not being found.
Encoding problem
The above are relatively common errors. The error I encountered here is caused by file encoding!
The error is similar to the picture below, only part of it is intercepted here:
Solution:
In Right-click on the project where the error occurred > Properties
Select "Resource" on the left, and select "Other" for Text file encoding on the right :UTF-8", click the "Apply"button.
Many friends reported that the problem still cannot be solved after the above steps. I just encountered such a problem recently;
In the article Java REST API Usage Example - Build Your Own Online Translation Tool Based on Cloud Platform + Cloud Service In the Java sample code downloaded from IBM Bluemix, after importing it into Eclipse, an error message similar to the above appears! As shown below:
For specific solutions, please refer to: HttpServlet cannot be resolved to a type
The above is the detailed content of Detailed explanation of the solution to the error xxx cannot be resolved to a type when writing JAVA using eclipse. For more information, please follow other related articles on the PHP Chinese website!