今天使用vscode 编写java代码做测试时候,发现这个问题,大概总结一下。

目录结构

bao -> Point.java

test.java

package bao;

public class Point<T> {// 此处可以随便写标识符号
private T x;
private T y; public void setX(T x) {// 作为参数
this.x = x;
} public void setY(T y) {
this.y = y;
} public T getX() {// 作为返回值
return this.x;
} public T getY() {
return this.y;
}
};
import bao.Point;

public class test {
public static void main(String[] args) {
//IntegerPoint使用
Point<Integer> p = new Point<Integer>();
p.setX(new Integer(100)) ;
System.out.println(p.getX()); //FloatPoint使用
// Point<Float> p = new Point<Float>();
// p.setX(new Float(100.12f));
// System.out.println(p.getX());
}
}

编译报错:The declared package does not match the expected package bao Java

大概的原因是编译器在bao这个包名下找不到Point.java, 所以需要在vscode中把根目录加入到java的sourcepath

使得编译器在寻找Point.java时,以项目根目录作为基准寻找路径,这样就编译通过了。

另外还有, 有的时候你在主方法里run或者debug的时候,编译器虽然能输出最后结果,但还是会报"Build failed xxxxx",我查了下官网,说是

然后一看,原来我现在的项目路径下包含许多子项目,只要有一个子项目的文件存在语法错误,我这个项目编译时就会报“build failed”,所以以后用vscode详见项目最好还是以每个项目作为根目录来建。

The declared package does not match the expected package Java的更多相关文章

  1. The declared package does not match the expected package

    The declared package does not match the expected package. 1.选中项目右击选择Build Path-->再选择Configure Bui ...

  2. 如何处理Eclipse错误消息 The declared package does not match the expected package

    我从github下载了一个开源项目后,导入到自己Eclipse之后,遇到了这个烦人的错误消息: The declared package "com.sap.smartService" ...

  3. The declared package &quot;com.dao&quot; does not match the expected package &quot;src.com.dao&quot;

    今天把项目代码上传到svn后出现例如以下错误:The declared package "com.dao" does not match the expected package ...

  4. org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

    题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后 ...

  5. CentOS7 - Package does not match intended download 问题解决

    yum 安装软件,有时会出现 Error: Package does not match intended download,这时需要彻底清除已有的下载,然后重新安装即可. $ sudo yum cl ...

  6. E: Unable to locate package clang-7 E: Unable to locate package clang++-7 E: Couldn't find any package by regex 'clang++-7'

    我的系统是Debian 9.8, 然后在装下面这两个包的时候老是提示找不到.然后再github上一问,过了几分钟就有大佬回复了,而且亲测有效 ~$ sudo apt-get -y install cl ...

  7. Provided id of the wrong type for class pojo.Books. Expected: class java.lang.Integer, got class java.lang.Long

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please ...

  8. 导入Unity插件时出现Failed to import package with error: Couldn't decompress package

    导入Unity插件时出现Failed to import package with error: Couldn't decompress package 一开始以为压缩包本身有问题,坏了 后来发现在父 ...

  9. org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau

    出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User ...

随机推荐

  1. Docker容器开机自动启动

     部署项目服务器时,为了应对停电等情况影响正常web项目的访问,会把Docker容器设置为开机自动启动. 在使用docker run启动容器时,使用--restart参数来设置: # docker r ...

  2. Go语言操作MySQL数据库

    Go语言操作MySQL数据库 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用 ...

  3. 喜怨交加C++

    作为被高中理综折磨几年立誓大学不学理工科类的文字爱好者,会学计算机是个意外.出于对理工科的不感兴趣,暑假期间也没有预习过编程知识.在对编程进行学习之前,我将它视为一门科目.一个专业.一项技能,唯独不是 ...

  4. 学习MeteoInfo二次开发教程(九)

    最终的MaskOut功能未能实现 另外,一个有用的,在指定位置显示图片: legend.MarkerType = MarkerType.Image; legend.ImagePath = " ...

  5. tensorflow/threading 用到的一些函数

    ---恢复内容开始--- import tensorflow as tf 1    tf.squeeze([1,2,3,4])  删除所有为1的维度   eg shape从(1,2,3,1)到(2,3 ...

  6. 基于bootstrap table配置的二次封装

    准备 jQuery js css 引用完毕 开始 如果对bootstrap table 的方法与事件不熟悉: Bootstrap table方法,Bootstrap table事件 <table ...

  7. 如何解决button,a,input标签自带蓝色边框

    通常我们会设置该标签outline:0;但是我在使用iview自带的button组件的时候,设置无效,经过测试只要设置 :focus{      outline:0; }  即可,方便有效

  8. HTTPS的内网访问和访问外网

    https://launchpad.support.sap.com/#/notes/2461900 https://wiki.scn.sap.com/wiki/display/Security/Tro ...

  9. Linux 添加新分区和 移动 /home到新挂载分区

    https://blog.csdn.net/lyd135364/article/details/78623119 https://www.cnblogs.com/saszhuqing/p/871664 ...

  10. drf框架使用之 路飞学城(第一天)

    1. 路飞学城第一天: 知识点 使用的是序列化与反序列化的使用: 1.创建一个公共相应的Json方法: #创建一个公共响应的类: class LuffyResponse(): def __init__ ...