简体   繁体   English

使用NetBeans将Java库导入项目时遇到麻烦

[英]Trouble with Importing Java Libraries into a project with NetBeans

I am having some issues with importing library which is needed to complete an assignment that I have been set. 我在导入库时遇到一些问题,这是完成我已设置的任务所需要的。

I'm not sure if I have added the library to the project, but the classes from the library appear to be in the libraries section of the project. 我不确定是否已将库添加到项目中,但是库中的类似乎位于项目的库部分中。

http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ

I added the libraries by right clicking on project1 and going to properties: 我通过右键单击project1并转到属性来添加库:

http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ#1 http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ#1

However whenever I have "package project1" at the top of Project1.java I receive a message that MaInput - which is one of the classes in this library - is not recognised: 但是,每当我在Project1.java的顶部有“ package project1”包时,我都会收到一条消息,指出无法识别MaInput-该库中的类之一:

cannot find symbol: symbol: class MaInput 找不到符号:符号:类MaInput

Whenever I take away "package project1" when trying to compile it reads: Error: Could not find or load main class project1.Project1 Java Result: 1. 每当我尝试编译时拿走“ package project1”时,它显示为:错误:无法找到或加载主类project1.Project1 Java结果:1。

The problem is that you are trying to access a class from default package from a named package and this is not allowed by the Java Specification. 问题是您正在尝试从命名包中的默认包中访问类,而Java规范不允许这样做。

So, in this case, create your assignment in the default package as well. 因此,在这种情况下,还要在默认程序包中创建您的作业。

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

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