d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Easy One About Packages > How Not To Use Default Package
Add Reply New Topic New Poll
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Sep 29 2012 05:54am
Im using netbeans and have learned that one should not use default package for larger programs.

Have created a package for all .gif files and a package for the logical classes.
Now the program cant even compile in the normal way.

Error message:

Quote
java.lang.NoClassDefFoundError: NewJFrame
Caused by: java.lang.ClassNotFoundException: NewJFrame
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: NewJFrame.  Program will exit.
Exception in thread "main" Java Result: 1


I can run the NewJFrame by rightclicking and choosing "run file". But now the images cant be seen.

Cant figure out how to import the images to NewJFrame

import programName.imagePackage;
or
import imagePackage;
doesnt work :(

Any help is welcome :)

Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 29 2012 06:40am
1. images belong in a folder, not a package. as a result, they do not get imported
2. when using the images in a folder, you must reference them by their folder. eg instead of "image1.jpg" you must say "images/image1.jpg" if they're in the images folder
3. that looks like a runtime error to me, not a compile time error
4. what is "the normal way" you run it? using the command line and saying "java NewJFrame"? or is it in a jar file? or something in netbeans? if it's in a jar file, make sure you're using a manfiest which specifies the new package. if it's in netbeans, make sure you set up runtime settings to point to this new package name
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Sep 29 2012 08:00am
ty for help :)

Quote
if it's in netbeans, make sure you set up runtime settings to point to this new package name


didnt know that, worked fine.

Code
1. images belong in a folder, not a package. as a result, they do not get imported


thought that was kind og the same thing. But "images/image1.jpg" also works. :)
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Sep 29 2012 09:02am
Quote (tigeranden @ Sep 29 2012 07:00am)

Code
1. images belong in a folder, not a package. as a result, they do not get imported


thought that was kind og the same thing. But "images/image1.jpg" also works.  :)


a folder can only contain one set of files.

a java package can contain more than one set of classes which, in turn, can be stored in more than one folder.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll