Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the symbol error that can not be found in java

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to solve symbol errors can not be found in java". In daily operation, I believe that many people have doubts about how to solve problems when they cannot find symbol errors in java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to solve symbol errors can not be found in java". Next, please follow the editor to study!

01. What does the "symbol not found" error mean

Let's take a look at a piece of code:

String s = String ()

An experienced Java programmer should be able to find the error in the above code, which lacks a new keyword. Therefore, this code will not pass during the compilation phase.

When we ignore the compilation error and try to run it, the program throws the following error.

"symbol not found" means either there is an obvious error in the source code or there is something wrong with the compilation. In short, we programmers did the trick, confused the compiler, it is a little inadequate, very innocent.

02. How does "symbol not found" happen?

1) spelling mistakes

After all, programmers are human beings, and people make mistakes.

The word is misspelled, such as spelling StringBuilder as StringBiulder.

StringBuilder sb = new StringBiulder (); / / symbol not found, class StringBiulder

The case is wrong, such as spelling StringBuilder as Stringbuilder.

StringBuilder sb = new Stringbuilder (); / / symbol not found, class Stringbuilder

2) undeclared variables

Sometimes we use a variable without declaring it.

System.out.println (sss); / / symbol not found, variable sss

Or the variable is out of scope.

For (int I = 0; I < 100; iTunes +)

{

System.out.println ("I is" + I)

}

The above code is not easy to find errors because there is only one more ";" before "{". The body of the for loop is cut into two parts, and the I in "{}" is outside the I range defined in "()".

3) the method is used incorrectly or does not exist

For example, how does Java get the length of arrays and strings? Length or length ()?

String [] strs = {"Silent King II"}

System.out.println (strs.length ()); / / symbol not found, method length ()

String str = "Silent King II"

System.out.println (str.length); / / symbol not found, variable length

4) forgot to import the class

When using a third-party class library, remember to import the class first.

StringUtils.upperCase ("abcd"); / / No symbol found, class StringUtils

However, you can set up automatic class import in IDEA to avoid this error.

.

There are a variety of reasons for the "symbol can not be found" error, and only a few of them are listed above. The root of the problem lies in the programmers themselves, and with the accumulation of programming experience and the help of integrated development tools, these errors can easily be found in the code writing phase.

How to fix the "symbol not found" error

In general, it's easy to fix "symbol not found" errors, either directly when writing code as prompted by IDE, or based on the stack log output after run.

The log gives the specific line number, as well as the type of error. According to the hint, think about what your code means, and then make specific actions to fix it. For example, the figure above reminds us that 35 lines of code have made a mistake and can't find the variable j, which means that we need to give the variable j a type declaration.

04. More complicated reasons

In actual projects, the reasons for the "symbol not found" error are often complex, but in most cases, it can be attributed to the following points:

The coding format is not correct. For example, it should be UTF-8, but some legacy projects will be set to GBK, GB2312, and so on.

The version of JDK does not match. For example, if some team members have JDK 1.6or JDK 8 installed on their computers, some of the new syntax after the upgrade will naturally conflict with the old version.

Upgrade of third-party class libraries. Some open source common libraries tend to be incompatible with older versions. For example, the latest version of the StringUtils class has a package of org.apache.commons.lang3, but it used to be org.apache.commons.lang.

The class name and method name are the same, but the package name is different and the parameters of the method are different, so it is easy to "cannot find the symbol" when using it.

When I first learned Java, the teacher asked us to write code in notepad, and then compile and run the code on the command line, which was really painful.

Often appear "can't find symbol" error, almost get started to give up. Because in the beginner stage, how can I remember so many rules of programming language? I often forget things and things. Moreover, notepad does not have a line number. It is deadly to find problems.

After suffering like this, I strongly advise beginners to stop using notepad programming (don't pretend to be forced) and go directly to IDE. If you have any problems, the tools will help you take it easy.

At this point, the study of "how to solve symbol errors can not be found in java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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: 228

*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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report