English 中文(简体)
在 Java处理具有某些价值的多个账户和账户[复制]
原标题:Issue with handling multiple accounts and accounts with certain values in Java [duplicate]
  • 时间:2014-09-07 01:12:08
  •  标签:
  • java

请解释“没有发现符号”、“没有决心符号”或“没有发现的代谢”错误(在 Java):

  • What do they mean?
  • What things can cause them?
  • How does the programmer go about fixing them?

www.un.org/Depts/DGACM/index_spanish.htm 这一问题旨在产生一个全面的Q&A介绍 Java这些共同汇编错误。

最佳回答

0. Is there any difference between these errors?

实际情况并非如此。 “没有发现符号”、“没有解决的符号”和“没有发现的代号”都意味着同样的事情。 (不同的 Java编者是由不同的人撰写的,不同的人用不同的学词来说同样的话。)

1. What does a "Cannot find symbol" error mean?

首先,这是compilation出的错误<>>1。 这意味着either 页: 1 你们在汇编这一文件方面存在着问题。

Your来源法典包括:

  • Keywords: like class, while, and so on.
  • Literals: like true, false, 42, X and "Hi mum!".
  • Operators and other non-alphanumeric tokens: like +, =, {, and so on.
  • Identifiers: like Reader, i, toString, processEquibalancedElephants, and so on.
  • Comments and whitespace.

A "Cannot find symbol" error is about the identifiers. When your code is compiled, the compiler needs to work out what each and every identifier in your code means.

“没有发现符号”的错误意味着汇编者不能这样做。 你的法典似乎指的是汇编者不理解的东西。

2. What can cause a "Cannot find symbol" error?

首先,只有一个原因。 汇编者对识别符号should<>>/em>界定的所有地点进行了研究,因此无法找到定义。 这可能是由一些事情造成的。 共同之处如下:

  • 通用标识:

    • Perhaps you spelled the name incorrectly; i.e. StringBiulder instead of StringBuilder. Java cannot and will not attempt to compensate for bad spelling or typing errors.
    • Perhaps you got the case wrong; i.e. stringBuilder instead of StringBuilder. All Java identifiers are case sensitive.
    • Perhaps you used underscores inappropriately; i.e. mystring and my_string are different. (If you stick to the Java style rules, you will be largely protected from this mistake ...)
    • Perhaps you are trying to use something that was declared "somewhere else"; i.e. in a different context to where you have implicitly told the compiler to look. (A different class? A different scope? A different package? A different code-base?)
  • For identifiers that should refer to variables:

    • Perhaps you forgot to declare the variable.
    • Perhaps the variable declaration is out of scope at the point you tried to use it. (See example below)
  • 对于应当采用的方法或外地名称的识别资料:

    • Perhaps you are trying to refer to an inherited method or field that wasn t declared in the parent / ancestor classes or interfaces.

    • 或许,你试图提及在你使用的类型中不存在(即没有申报)的方法或领域;例如rope.push(2

    • 也许你试图将一种方法作为领域,或反之亦然;例如rope>.lengthsomeArray.length()。

    • 也许你错误地以阵列而不是阵列要素运作;例如,

          String strings[] = ...
          if (strings.charAt(3)) { ... }
          // maybe that should be  strings[0].charAt(3) 
      
  • 应为类别名称的识别符号:

    • 也许你会放弃进口这一类别。

    • 也许你使用“星号”进口,但你进口的任何包裹都界定了该类。

    • 或许请您通过<代码>新。 a 包括:

          String s = String();  // should be  new String() 
      
    • 也许你正在试图进口或以其他方式使用default Pack上宣布的一类;即没有<代码>的类别:<<<> > >/代码>的一类。

      Hint: 学习包裹。 你们只应使用一揽子缺省申请,这些申请包括一个类别......或一个范围很广的 Java源文档。

  • 如果是哪类或例(例如,方法或领域)成员似乎有:

    • Perhaps you have declared a nested class or a generic parameter that shadows the type you were meaning to use.
    • Perhaps you are shadowing a static or instance variable.
    • Perhaps you imported the wrong type; e.g. due to IDE completion or auto-correction may have suggested java.awt.List rather than java.util.List.
    • Perhaps you are using (compiling against) the wrong version of an API.
    • Perhaps you forgot to cast your object to an appropriate subclass.
    • Perhaps you have declared the variable s type to be a supertype of the one with the member you are looking for.

问题常常是上述问题。 例如,或许你们“星号”进口java.io.*,然后试图使用<代码>Files . ......这一类别载于java.nio而不是java.io。 或者,你打算撰写<代码>File......>,is a 类别,载于java.io


这里的一个例子是,不准确的透镜可导致“没有发现符号”错误:

List<String> strings = ...

for (int i = 0; i < strings.size(); i++) {
    if (strings.get(i).equalsIgnoreCase("fnord")) {
        break;
    }
}
if (i < strings.size()) {
    ...
}

这将给<代码>i>的“Cannot探测器”差错。 虽然我们此前已宣布<代码>i,但该声明仅限<>>>在范围上公布于<>>for statement and its body. <代码>i,载于if的说明cannot see that declaration of i。 页: 1

(此处的适当更正可以是将if statement within the loop, or toclari before the loop.]


这里的一个例子是,打字导致似乎无法复制的“Cannot发现符号”错误:

for (int i = 0; i < 100; i++); {
    System.out.println("i is " + i);
}

这将使你在<代码>印本/代码>上出现汇编错误。 不能找到<代码>i。 但(我听到你说)我确实宣布了!

问题在于<代码>{之前的斜线半分辨率(;)。 Java语的同义词在这方面界定了一种半殖民地,即:empt.>。 空话随后成为<>><的左体。 因此,该法典实际上意味着:

for (int i = 0; i < 100; i++); 

// The previous and following are separate statements!!

{
    System.out.println("i is " + i);
}

<代码>{>>>>><>>>>> > 栏目为“NOT”栏,因此,在栏目中,先前的“<代码>i在<>for上的声明为out of scope。


此处是“没有发现符号”错误的另一个例子,该错误是由打字造成的。

int tmp = ...
int res = tmp(a + b);

Despite the previous declaration, the tmp in the tmp(...) expression is erroneous. The compiler will look for a method called tmp, and won t find one. The previously declared tmp is in the namespace for variables, not the namespace for methods.

在我所举的例子中,方案管理员实际上离开了运营商。 他打算写的是:

int res = tmp * (a + b);

There is another reason why the compiler might not find a symbol if you are compiling from the command line. You might simply have forgotten to compile or recompile some other class. For example, if you have classes Foo and Bar where Foo uses Bar. If you have never compiled Bar and you run javac Foo.java, you are liable to find that the compiler can t find the symbol Bar. The simple answer is to compile Foo and Bar together; e.g. javac Foo.java Bar.java or javac *.java. Or better still use a Java build tool; e.g. Ant, Maven, Gradle and so on.

There are some other more obscure causes too ... which I will deal with below.

3. How do I fix these errors ?

一般来说,你首先将汇编中的错误编成“<>>。

  • Look at the line in the file indicated by the compilation error message.
  • Identify which symbol that the error message is talking about.
  • Figure out why the compiler is saying that it cannot find the symbol; see above!

之后,请您就您的法典应该说什么。 之后,你终于完成了对你的来源法典需要做的修改。

Note that not every "correction" is correct. Consider this:

for (int i = 1; i < 10; i++) {
    for (j = 1; j < 10; j++) {
        ...
    }
}

假设汇编者说<代码>j的“没有发现符号”。 我可以采取许多方法“确定”:

  • I could change the inner for to for (int j = 1; j < 10; j++) - probably correct.
  • I could add a declaration for j before the inner for loop, or the outer for loop - possibly correct.
  • I could change j to i in the inner for loop - probably wrong!
  • and so on.

The point is that you need to understand what your code is trying to do in order to find the right fix.

4. Obscure causes

在这里,“没有发现符号”似乎无法复制......直到你更接近。

  1. www.un.org/Depts/DGACM/index_spanish.htm 校正 如果你正在使用一种管理建筑道路和项目依赖性的电算法或建筑工具,你可能会与依赖者犯错误;例如,没有依赖,或选择错误版本。 如果你使用建筑工具(Ant、Maven、Gradle等),就检查项目建筑档案。 如果你正在使用一个发展信息网,则检查该项目的修建道路组合。

  2. www.un.org/Depts/DGACM/index_spanish.htm 页: 1 也许你正在尝试汇编使用当地变量类型推论的源代码(即:var申报),其编制时间较长或更长的<代码>-source。 http://www.ohchr.org。 查阅您的JDK版本和您的建筑档案,(如果是在民主选举学会的环境下进行)。

  3. www.un.org/Depts/DGACM/index_spanish.htm 页: 1 有时,新的 Java方案家不理解 Java工具链如何发挥作用,或避风港如何实施可重复的“造型程序”,例如利用国际民主和选举援助学会、Anton、Maven、Gradle等。 在这种情况下,方案管理员可以最终追索他的尾声,寻找一个虚幻的错误,即实际<>。 造成这种情况的原因是,没有适当修改法典。

    这方面的另一个例子是,当你使用(Java 9+)java SomeClass.java汇编和操作一个类别。 如果该类别取决于另一类,即您所汇编的编号(或再编),那么你就应当获得“没有解决符号”的错误,指第二类。 其他来源档案并不自动汇编。 <代码>java 新的“完整和运行”模式的设计并不适用于使用多种来源代码文档的方案。

  4. An earlier build problem: It is possible that an earlier build failed in a way that gave a JAR file with missing classes. Such a failure would typically be noticed if you were using a build tool. However if you are getting JAR files from someone else, you are dependent on them building properly, and noticing errors. If you suspect this, use tar -tvf to list the contents of the suspect JAR file.

  5. IDE issues: People have reported cases where their IDE gets confused and the compiler in the IDE cannot find a class that exists ... or the reverse situation.

    • 如果民主选举学会与错误的JDK版本混为一谈,就会出现这种情况。

    • This could happen if the IDE s caches get out of sync with the file system. There are IDE specific ways to fix that.

    • 这可能是民主选举学会的模范。 例如,@Joel Costigliola描述了一种情况,即Eclipse没有正确处理Maven的“测试”树:。 (显然早在很久以前就已固定了这种 b。)

  6. <>Android issues: 当你为安康进行方案规划时,你有与<代码>R有关的“没有发现符号”差错,知道<代码>R符号>符号由<编码>context.xml文档界定。 核对<代码>context.xml文档正确无误,正确无误,相应的<代码>R 编写/汇编了班级档案。 注意 Java符号是敏感的,因此相应的XML树脂也敏感。

    甲型六氯环己烷的其他符号错误可能是由于先前提到的原因;例如,特定亚体版本中不存在或错误的受抚养人、不正确的包装名称、方法或没有存在的田地、拼写/打字错误等等。

  7. http://www.un.org。 我看到了汇编者抱怨<>代号<>/代码>在下述情况下是一个不为人知的象征的情况:

    String s = ...
    String s1 = s.substring(1);
    

    它指出,方案管理员建立了自己的版本<代码>String,他的类别版本没有界定substring方法。 I ve see people do this with System,Scanner and other levels.

    <>Lesson: Don t用与普通图书馆课程相同的名称来界定自己的课程!

    这个问题也可以通过使用完全合格的名字来解决。 例如,在上述例子中,方案主管could。 注

    java.lang.String s = ...
    java.lang.String s1 = s.substring(1);
    
  8. <>Homoglyphs>: 如果你使用UTF-8在源文档中编码,就有可能有look<>>>识别码。 同样,但事实上有所不同,因为它们含有同质素。 See this page for more information.

    您可以避免这种情况,将海因限制为ASCII或拉丁-1,将其作为源文档编码,并利用 Javauxx,以其他特性逃避。


1 - If, perchance, you do see this in a runtime exception or error message, then either you have configured your IDE to run code with compilation errors, or your application is generating and compiling code .. at runtime.
2 - The three basic principles of Civil Engineering: water doesn t flow uphill, a plank is stronger on its side, and you can t push on a rope.

问题回答

You ll also get this error if you forget a new:

String s = String();

相对

String s = new String();

由于电话没有<代码>新 关键词将尝试和寻找一种称为<代码>的(当地)方法,其中无争论可循的<>标准>,而且可能无法界定方法签名。

SOLVED

利用英特尔利J

选择Build ->Rebuild Project 解决

www.un.org/Depts/DGACM/index_spanish.htm 可变性的另一个实例是。

正如我已经看到过几次这样的问题,也许可以再举一个例子来说明什么是非法的,哪怕是可能的话。

考虑这一法典:

if(somethingIsTrue()) {
  String message = "Everything is fine";
} else {
  String message = "We have an error";
}
System.out.println(message);

该法典无效。 由于“<代码>message”这两个变量在各自范围之外都看不出,因此此处的方括号为{}

您可以说:“......在<条码>后界定的电文,即s

但你错了。

Java没有<代码>Free(或>delete的操作者,因此,它必须依靠跟踪可变的范围,以发现变数不再使用(同时提及这些原因的变量)。

It s especially bad if you thought you did something good. I ve seen this kind of error after "optimizing" code like this:

if(somethingIsTrue()) {
  String message = "Everything is fine";
  System.out.println(message);
} else {
  String message = "We have an error";
  System.out.println(message);
}

“Oh,有重复的代码,请将这一共同线拉开”——“并”;

The most common way to deal with this kind of scope-trouble would be to pre-assign the else-values to the variable names in the outside scope and then reassign in if:

String message = "We have an error";
if(somethingIsTrue()) {
  message = "Everything is fine";
} 
System.out.println(message);

在Eclipse中找到这一错误的方法之一:

  1. Define a class A in src/test/java.
  2. Define another class B in src/main/java that uses class A.

Result : Eclipse will compile the code, but maven will give "Cannot find symbol".

根本原因:Eclipse正在使用一条主要树木和试验树木的综合建筑道路。 不幸的是,它不支持对Eclipse项目的不同部分使用不同的建筑道路,而这正是Maven的要求。

Solution :

  1. Don t define your dependencies that way; i.e. don t make this mistake.
  2. Regularly build your codebase using Maven so that you pick up this mistake early. One way to do that is to use a CI server.

“没有发现”是指,如果你发现这种错误,可以找到适当的变数、方法、分类等的汇编者,首先,你们都想在出现错误的群落时找到代码线。 那么,在使用之前,你会发现哪些变量、方法或类别没有定义。 经确认,变数、方法或类别可以用于以后的需要...... 考虑以下例子。

页: 1

class demo{ 
      public static void main(String a[]){
             System.out.print(name);
      }
}

现在看着结果。

“entergraph

这种错误说,“无法找到可变的名称”。 对名称变量的界定和初步确定值可取消这一错误。 确实如此,

class demo{ 
      public static void main(String a[]){

             String name="smith";

             System.out.print(name);
      }
}

现在看看新的产出......

“entergraph

Ok Successfully solved that error..At the same time , if you could get "can not find method " or "can not find class" something , At first,define a class or method and after use that..

If you re getting this error in the build somewhere else, while your IDE says everything is perfectly fine, then check that you are using the same Java versions in both places.

例如,Java 7和Java 8有不同的亚特兰大,因此,在旧的Java版本中,没有APICA,就会造成这一错误。

There can be various scenarios as people have mentioned above. A couple of things which have helped me resolve this.

  1. If you are using IntelliJ

OR

  1. 另一项目提到这个类别,我的项目的格拉斯建筑档案没有增加依赖性。 因此,我补充说,使用依赖性

    <代码>compile Project (:another) 项目......

它发挥了作用。 HTH!

如果ec木 build铺路被绘制为7,8,而x子项目则提到 higher版(9,10,11等)高于7,8 您需要用om子文档更新。

In Eclipse if Java is mapped to Java version 11 and in pom.xml it is mapped to Java version 8. Update Eclipse support to Java 11 by go through below steps in eclipse IDE Help -> Install New Software ->

Paste following link http://download.eclipse.org/eclipse/updates/4.9-P-builds at Work With

or

添加(备用窗口将开放)——和

Name: Java 11 support Location: http://download.eclipse.org/eclipse/updates/4.9-P-builds

之后更新了“Maven”版,载于pom.xml。 档案

<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

Finally do right click on project Debug as -> Maven clean, Maven build steps

我也正在发现这一错误。 (我去了,我去了这个页)

Problem: I was calling a static method defined in the class of a project A from a class defined in another project B. I was getting the following error:

error: cannot find symbol

Solution: I resolved this by first building the project where the method is defined then the project where the method was being called from.

you compiled your code using maven compile and then used maven test to run it worked fine. Now if you changed something in your code and then without compiling you are running it, you will get this error.

解决办法:再次汇编,然后进行测试。 对我来说,它这样做了。

在我的案件中,我不得不采取以下行动:

  1. Move context.xml file from src/java/package to the resource directory (IntelliJ IDE)
  2. Clean target directory.

For hints, look closer at the class name name that throws an error and the line number, example: Compilation failure [ERROR] applicationsxxxxx.java:[44,30] error: cannot find symbol

One other cause is unsupported method of for java version say jdk7 vs 8. Check your %JAVA_HOME%

We got the error in a Java project that is set up as a Gradle multi-project build. It turned out that one of the sub-projects was missing the Gradle Java Library plugin. This prevented the sub-project s class files from being visible to other projects in the build.

在将Java图书馆原始材料添加到分项目build.gradle后,该错误消失:

plugins {
    ...
    id  java-library 
}

Re:4.4: An early Building problem in Stephen C sillian response:

I encountered this scenario when developing an osgi application.
I had a java project A that was a dependency of B. When building B, there was the error:

Compilation failure: org.company.projectA.bar.xyz does not exist

但是,在粗略情况下,根本没有编纂问题。

Investigation
When i looked in A.jar, there were classes for org.company.projectA.foo.abc but none for org.company.projectA.bar.xyz.

失踪班次的原因是,在<代码>A/pom.xml中,出口相关包裹的条目。

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    ...
    <configuration>
        <instructions>
            ....
            <Export-Package>org.company.projectA.foo.*</Export-Package>
        </instructions>
    </configuration>
</plugin>

Solution
Add the missing packages like so:

<Export-Package>org.company.projectA.foo.*,org.company.projectA.bar.*</Export-Package>

and rebuild everything.

Now the A.jar includes all the expected classes, and everything compiles.

我正在经历以下错误。

java: cannot find symbol
  symbol: class __

确定这一点

我尝试使兰博克得以成功,重新恢复了内利,但下面为我工作。

Intellij Preferences ->Compiler -> Shared Build process VM Options and set it to

  -Djps.track.ap.dependencies=false

页: 1

mvn clean install

Optional.isEmpty()

我习惯使用<代码>! 现在,在使用<代码>Gradle时,在指挥线上(在JDK8上运行),即汇编任务中新出现的错误。

Why?

引自(注意最后一行):

boolean java.util.Optional.isEmpty()

If a value is not present, returns true, otherwise false.
Returns:true if a value is not present, otherwise false
Since:11




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签