In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the common errors in Java development". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "what are the common errors in Java development" together.
compiler errors
Compiler error messages are generated when Java software code is executed by the compiler. It is important to remember that a compiler may throw multiple error messages for a single error. So fixing the first bug and recompiling can fix a lot of problems.
1. "... predictable"
This type of error occurs when code is missing. Maybe a parenthesis or semicolon is missing.
Such error messages often do not pinpoint exactly where the error occurred. To find errors, it is recommended that:
Make sure all left brackets have matching right brackets.
Check in the prompt before the line of code. This Java software bug is not something that the compiler should be concerned about; it should be left to do the rest of the work.
Sometimes a character, such as a left parenthesis, should not be written at the beginning of Java code. The result is that developers don't write right parenthesis to make pairs.
Here, Xiaobian built a front-end learning exchange button group: 132667127, the latest front-end information and advanced development tutorials I collated myself. If you want to need it, you can add groups to learn and exchange together.
2. "Unclosed String Expression"
The "Unclosed String Expression" error message occurs at the end of a Sting expression without quotation marks, and the error message is prompted on the same line where the error occurred. A String expression is a value in the source code.
Errors usually occur when:
String expression ends without quotation marks. This error can be easily corrected by using quotation marks at the end of a String expression
String expression exceeds one line. Long String expressions can be split into multiple expressions and concatenated with "+."
Quotation marks are elements in String expressions that are not escaped with underscores "\."
3. "Illegal expression start"
There are many reasons for the "illegal expression start" error. But it ended up being classified as one of the less useful error messages. Some developers say this is caused by bad code.
Typically, expressions are created to generate new values or assign values to variables. The compiler expects to find an expression, but cannot find it because the syntax does not match expectations. This error can be found in the following statements.
4. "No symbol found."
This is a very common problem because all identifiers in Java need to be declared before they can be used. When compiling code, the compiler does not understand the meaning of the identifier.
There are many reasons why you might encounter a "symbol not found" message:
Identifiers may be spelled differently when declared than when used in code.
This variable has never been declared.
The variable is used in a different location than the scope in which it is declared.
Class is not imported.
5. "Public class XXX should appear in file"
The message "Common class XXX should appear in files" appears when class XXX and Java program file names do not agree. Source code is compiled only if the class name is the same as the Java file name.
To fix this situation:
Class name is the same as file name.
Make sure the case of the two names is the same.
6. "Incompatible types"
Incompatible types are logical errors that are triggered when an assignment statement attempts to match a variable to a type expression. Usually occurs when code tries to write text characters into integers and vice versa. This is not a Java syntax error.
When the compiler gives an "incompatible type" message, there really isn't a simple fix:
There are functions that can convert types.
Developers may need to modify the code as intended.
7. "Invalid method declaration; requirement return type"
This error indicates that the return type of the method is not explicitly stated in the method signature.
There are several ways to trigger an "invalid method declaration; requirement return type" error:
Forgot the description Return type
If the method has no return value, then you need to use "void" to indicate the return type in the method signature.
The constructor name does not need to specify the return type. However, if there is an error in the constructor name, the compiler treats the constructor as a method without the specified type.
8. "Method X in class Y cannot be applied to the given type"
This error message is one of the most useful error messages in Java. It explains how method signatures invoke the wrong arguments.
The method expects certain parameters defined in the method declaration when called. Check method declarations and invoke methods carefully to ensure that declared and invoked parameters are compatible.
9. "Missing return statement"
When a method is missing a return statement, a "missing return statement" error occurs. Every method (not void type) that returns a value must have a literal statement that returns the value in order to call that value outside the method.
Here are some reasons why the compiler throws a "missing return statement" message:
The return statement was incorrectly omitted
A method returns no value, but is not declared void in the method signature
10. "Accuracy may be lost"
When more information than a variable can hold is assigned to that variable, the "precision may be lost" problem occurs. If this happens, the excess information will be thrown away. If this is OK, then the code needs to explicitly declare the variable as the new type.
The "precision may be lost" error occurs when:
Assign a real number to an integer variable.
Assigns a double precision floating-point number to an integer variable.
11. "End of file reached when parsing"
This error message often occurs when Java programs lack the "}" symbol. Usually adding the "}" symbol to the end of the code can quickly solve this problem.
The result of running the above code is the following error:
Coding tools and proper code indentation make it easier to find these incorrect braces.
This example shows how missing braces can result in the error message "End of file reached while parsing."
12. "Statement unreachable"
"Statement unreachable" occurs when a statement is placed in a position where it will not be executed. Usually after a break statement or return statement.
This error can usually be resolved by simply moving the return statement.
13. "Variable x may not be initialized"
This problem occurs when local variables within a method are not initialized at the time of declaration. This error occurs when a variable is not initialized but appears in an if statement.
14. "Operator... cannot be applied to x"
This happens when operators are applied to types that do not define how they are used.
This problem often occurs when Java code tries to perform mathematical calculations using string types. To solve it, string needs to be converted to integer or float.
15. "Types that cannot be converted"
The "unconvertible type" error occurs when Java code attempts an illegal conversion.
For example, boolean cannot be converted to int.
16. "Missing return value"
When the return statement returns an incorrect type, you receive a "missing return value" message. For example, the following code:
The following error message is returned:
Usually, those return statements don't return anything.
17. "A method of return type void cannot return a value"
This Java error occurs when a method of return type void attempts to return any value, such as the following example:
This problem is usually solved by changing the method signature to match the return type of the return statement. In the above example void can be changed to int:
18. "Non-static variables... Cannot be referenced in static context "
This error occurs when the compiler attempts to access a non-static variable in a static method.
To solve the problem of "non-static variables... There are two ways to avoid the "cannot be referenced in static context" error:
Declare variables as static variables in the signature.
Example of creating a non-static object in a static method
19. "Non-static methods... Cannot be referenced in static context "
This happens when Java code tries to call a non-static method in a non-static class. For example, the following code:
The following error will be returned:
To invoke a non-static method in a static method, you can declare an instance of a class to invoke the non-static method.
20. "(array)NotInitialized"
When an array is declared but not initialized, you get the message "(array) not initialized." Arrays are fixed in length, so each array needs to be initialized to its actual length.
Thank you for reading, the above is "Java development common errors what" content, after the study of this article, I believe we have a deeper understanding of Java development common errors what this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.