0

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

grdryn
  • 1,972
  • 4
  • 19
  • 28
user3419585
  • 13
  • 1
  • 1
  • 7
  • 2
    I'm not sure what you're trying to do, but this is not related to the Java SDK. There's no such package in the SDK. Maybe you are trying to use an external library, but one which has weird naming: usually (read: almost always) packages start with a lowercase character. – Erik Pragt Jul 19 '14 at 11:27
  • Why do you need `Utilities.Keyboard`? – Thorbjørn Ravn Andersen Jul 19 '14 at 12:11

2 Answers2

0

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.

Community
  • 1
  • 1
Robert Snyder
  • 2,399
  • 4
  • 33
  • 65
-3

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.

Amitesh Rai
  • 866
  • 11
  • 21
  • i put in a down vote for 2 reasons. one is that because I use netbeans, eclipose, and IntelliJ and all 3 of them don't have the same keyboard shortcuts except for ctrl+o for open, ctrl+s for save, ctrl+shift+s for save all. all the other common keyboard shortcuts that I can think of are different. Second reason I give a downvote is because using the IDE can give important lessons in learning java just the same as using a text editor, but getting the feedback from the IDE is quicker. Now relying on the IDE for GUI generation... ok I'll agree with you there. – Robert Snyder Jul 19 '14 at 11:59
  • BTW CTRL+SHIFT+O opens a project in Netbeans – Robert Snyder Jul 19 '14 at 12:00
  • @RobertSnyder, that's why i mentioned CTRL+SHIFT+O to be Eclipse specific – Amitesh Rai Jul 19 '14 at 12:03
  • @RobertSnyder, regarding using an IDE or not. So i would rather suggest not use an IDE to anyone who has just started the programming. Off-course, when you have learnt the language fundamentals then an IDE provides much more to learn and expore the libraries. – Amitesh Rai Jul 19 '14 at 12:07