简体   繁体   中英

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

I created the following java program

/*
 * 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. 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. Next open up the projects tab (if you can't find the projects tab you can use the keyboard shortcut of ctrl+1). Once it is open right click on the Libraries and click on Add JAR/Folder. Navigate to your jar file and add it.

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. you can click on said lightbulb and it will suggest a fix or 2. Hope this helps

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,. 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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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