Results 1 to 15 of 15
Like Tree1Likes
  • 1 Post By Advert

Thread: New to java :)

  1. #1
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default New to java :)

    Hi
    I just started to learn java programming and when i tested to draw some 2D graphics i got a error that package applet dont exist, My question: How do i import packages to Netbeans?
    Thanks in advance/Advert
    javalearner12 likes this.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Can you show the full text of your error message?
    Also show all the import statements at the beginning of your source program.

  3. #3
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    Java Code:
    import java.applet.*;
    import java.awt.*;
    
    public class HelloWorld extends Applet
    {
      public void paint (Graphics g)
      {
    	g.drawString("Hello World!", 50, 25);
      }
    This is the site where im trying to learn from Java Game Programming Part I: The Basics

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    What errors do you get when you compile that program?
    I am able to compile it with no errors (after I add the ending })

  5. #5
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    run:
    java.lang.NoClassDefFoundError: draw/Draw
    Caused by: java.lang.ClassNotFoundException: draw.Draw
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
    Could not find the main class: draw.Draw. Program will exit.
    Exception in thread "main" Java Result: 1

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    The java program can not find the class Draw in the package draw.
    Make sure the classpath is set to the folder holding the draw folder and that the Draw.class file is in the draw folder.

  7. #7
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    The java program can not find the class Draw in the package draw.
    Make sure the classpath is set to the folder holding the draw folder and that the Draw.class file is in the draw folder.
    Ok, Thanks for your help.

  8. #8
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

    Default

    I just compiled and ran that code with no problems.

    You will need to make sure the proper package is there as well. In Netbeans all Java source code files need a package.

    Remember, that is an Applet not an Application. There is no main in an Applet. You will need to use Netbeans Applet Viewer by doing a Shift-F6.
    Last edited by stchman; 08-04-2011 at 11:44 PM.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    All Java source code files need a package.
    I'd replace "need" with another way of making the point about namespaces etc.

    I have a disk full of java source programs without a package statement.

  10. #10
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    Sorry but where do i change that?
    and i still get a error in the editor that java.applet is a incorrect package

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Were is the error messages like you posted in #5

  12. #12
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    I'd replace "need" with another way of making the point about namespaces etc.

    I have a disk full of java source programs without a package statement.
    All java source files in Netbeans need a package, I edited the post to be more clear.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    You might guess that I don't use an IDE and didn't know that.

  14. #14
    Advert is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    What do you that is familiar with java recommend to edit and compile java with?

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    My choice for beginners would be an editor with java syntax highlighting. And a command prompt to compile and test.
    There is so much that is hidden by an IDE that you need to know. Doing things manually for a while until you understand what is happening and then move into an IDE that provides a lot of help.

    I have an enhanced editor with projects with settable command lines that I've used for over a dozen years. Every time I try an IDE I find them so slow and cumbersome that I give up after a week. Before Java moved into generics so heavily, I wrote all my code (as a hobby) in 1.4. I have a compiler that will compile most of my code faster than I can hit Enter and look up to see the results. Sub sub second.
    Now I have to use Oracles's slower compiler like everyone else.
    Last edited by Norm; 08-05-2011 at 12:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •