简体   繁体   English

如何将Java SDK导入NetBeans?

[英]How do I import the Java SDK's into NetBeans?

Hi I'm new to Java and NetBeans IDE 7.4 I've installed JDK 7u45 Windows and NetBeans 7.4 嗨,我是Java和NetBeans IDE 7.4的新手,我已经安装了JDK 7u45 Windows和NetBeans 7.4

I created the following java program 我创建了以下Java程序

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package readnumbers;
import Utilities.Keyboard;

/**
 *
 * @author Sinatra
 */
public class ReadNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        // TODO code application logic here
        double dNum1, dNum2, dNum3;
        double dAnswer;

        System.out.println("This is a heading");
        System.out.println("Enter a number");
        dNum1 = Keyboard.getDouble();

    }
}

I'm getting the following error: error: package Utilities does not exist. 我收到以下错误:错误:软件包实用程序不存在。

Please help 请帮忙

I'm a little unclear about your exact problem. 我对您的确切问题不太清楚。 As others have pointed out any 3rd party libraries will follow the java naming convention for their package names which means that it will be in lowercase letters. 正如其他人指出的那样,任何第三方库都将遵循Java命名约定作为其程序包名称,这意味着它将使用小写字母。 So since I can't assume that you've added the SDK (JAR library) to your netbeans project you will need to know where said JAR library is located on your harddrive. 因此,由于我不能假定您已将SDK(JAR库)添加到您的netbeans项目中,因此您需要知道所说的JAR库在硬盘驱动器上的位置。 Next open up the projects tab (if you can't find the projects tab you can use the keyboard shortcut of ctrl+1). 接下来打开项目标签(如果找不到项目标签,则可以使用ctrl + 1键盘快捷键)。 Once it is open right click on the Libraries and click on Add JAR/Folder. 打开后,右键单击“库”,然后单击“添加JAR /文件夹”。 Navigate to your jar file and add it. 导航到您的jar文件并添加它。

Before you do that though I would suggest looking at the lightbulb with the red exclimation mark. 在您这样做之前,我建议您看一下带有红色感叹号的灯泡。 This indicates that netbeans has a possible suggestion to fix your compiler error. 这表明netbeans可能会建议您修复编译器错误。 you can click on said lightbulb and it will suggest a fix or 2. Hope this helps 您可以点击该灯泡,然后提出修复建议或2。

EDIT 编辑

also looking at your code, it suggests that you want to get keyboard input. 还查看您的代码,它表明您想获取键盘输入。 I think this Question might help you. 我认为这个问题可能对您有帮助。 It's from here about how to get keyboard input. 这是关于如何获取键盘输入的信息。

You don't need to import Java's whole SDK,. 您不需要导入Java的整个SDK。 Only the classes from libraries are required in your program and they should be imported only when you require those library classes. 程序中仅需要库中的类,并且仅在需要这些库类时才应导入它们。

Since you are using the IDE, to import any class from the libraries, just type the class name and press CTRL+SHIFT+O on your keyboard, and that class will be automatically imported for you(at least it works in Eclipse, you can try it in netbeans). 由于您使用的是IDE,因此要从库中导入任何类,只需键入类名称并在键盘上按CTRL + SHIFT + O,该类将自动为您导入(至少在Eclipse中有效,您可以在netbeans中尝试一下)。

However, if you are manually importing the class libraries, then always remember that package names always starts with lowercase letters and class names Should always be starting with Uppercase letters. 但是,如果要手动导入类库,则请始终记住,程序包名称始终以小写字母开头,而类名称应始终以大写字母开头。

Since you are new to Java, my personal advice would be get rid of IDE first and start writing your codes using a simple Text Editor, like notepad, notepad++ or sublime Text2, or whatever you like. 由于您是Java的新手,所以我个人的建议是先摆脱IDE并开始使用简单的文本编辑器(例如notepad,notepad ++或sublime Text2)或您喜欢的任何东西编写代码。

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

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