简体   繁体   English

为什么我不能创建Java列表?

[英]Why can't I create the Java list?

I can't make the code below run. 我无法运行下面的代码。 The feedback I get is "cannot find symbol" and the place where it occurs is at the letter 'i' on the line "private List products;". 我得到的反馈是“找不到符号”,它出现的位置在“私人列表产品”行上的字母“ i”上。

The error message is: [ERROR] \\Users\\Filip\\Dropbox\\EclipseWorkspace\\ProductsCarts\\src\\main\\java\\hello\\Cart.java:[8,14] error: cannot find symbol 错误消息是:[错误] \\ Users \\ Filip \\ Dropbox \\ EclipseWorkspace \\ ProductsCarts \\ src \\ main \\ java \\ hello \\ Cart.java:[8,14]错误:找不到符号

I don't know if it matters but I am using the Spring Boot framework and Maven. 我不知道这是否重要,但是我正在使用Spring Boot框架和Maven。

What is wrong? 怎么了? (Observe that the class Cart consist of a list of Product. The code for a product is presented below this on) (请注意,类Cart由产品列表组成。产品代码显示在此下方)

package main.java.hello;

import java.util.LinkedList;
import java.util.List;

public class Cart {
    private int id;
    private List<Product> products;

    public Cart(int id){
        this.id=id;
        //products=new LinkedList<Product>();

    }
}

The code for Product: 产品代码:

package main.java.hello;

public class Product {
    private int id;
    private String name;
    private double priceIncVat;
    private double vatPercentage;
    private double vatAmount;



    public Product(int id, String name, float priceIncVat, float vatAmount){
        this.id=id;
        this.name=name;
        this.priceIncVat=priceIncVat;
        this.vatPercentage=(vatAmount/priceIncVat);

    }

}

Here is the complete error message: 这是完整的错误消息:

 [ERROR] \Users\Filip\Dropbox\EclipseWorkspace\ProductsCarts\src\main\java\hello\Cart.java:[8,14] error: cannot find symbol
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project gs-handling-form-submission: Compilation failure
[ERROR] \Users\Filip\Dropbox\EclipseWorkspace\ProductsCarts\src\main\java\hello\Cart.java:[8,14] error: cannot find symbol
[ERROR] -> [Help 1]
 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
C:\Users\Filip\Dropbox\EclipseWorkspace\ProductsCarts>

You're mixing directory layouts. 您正在混合目录布局。 Maven puts source code in src/main/java , not just src . Maven将源代码放入src/main/java ,而不仅仅是src Your package declaration thinks you're just putting the code in src . 您的软件包声明认为您只是将代码放入src Remove the extra components, and you may not be using m2eclipse to manage the Eclipse build; 除去额外的组件,您可能不会使用m2eclipse来管理Eclipse构建。 install and import your project as a Maven project if not. 如果没有,则将项目安装并导入为Maven项目。

Just create the sample java project and install the "m2eclipse" plugin to manage the eclipse build. 只需创建示例Java项目并安装“ m2eclipse”插件即可管理Eclipse构建。 and then right click on your project go to configure and click on convert to maven option then your project was converted to maven, in you project directory root folder pom.xml file was generated. 然后右键单击您的项目,进行配置,然后单击“转换为maven”选项,然后将项目转换为maven,这是在项目目录根文件夹pom.xml文件中生成的。 and check with your package folder like src/main/java and src/test/java etc. then create package in this location src/main/java and create the java file. 并检查您的包文件夹,如src / main / java和src / test / java等。然后在此位置src / main / java中创建包并创建Java文件。 if u need to add any jar files for your project just update the pom.xml file it contains 如果您需要为您的项目添加任何jar文件,只需更新其中包含的pom.xml文件

<groupId>....</groupid>
<artifactId>...</artifactId>
<version>....</version>`enter code here`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM