DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5

Thread: Using Packages

  1. #1
    Join Date
    Sep 2003
    Posts
    16

    Using Packages

    Hello,
    I'm relatively new to Java. I've made up a package and I'm trying to implement it in an Applet. I imported it. However, any time I try to use it, the applet gives an error message stating "Applet notinited". Anytime I try to use the class, imageFile f = new imageFile("somestringhere.jpg"); it gives the above error message. Any clues what the deal is? Is there anything different I need to do with an Applet when using packages?
    Jerod Brown

  2. #2
    Join Date
    Mar 2003
    Posts
    834

    Question

    What does the Java console say? (in IE, it's Tools -> Sun Java Console)

    Have you fully qualified your main applet file? e.g. com.sony.MyApplet
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Sep 2003
    Posts
    16
    These are the messages its saying in the console:

    java.lang.NoClassDefFoundError: radss/imageFile
    java.lang.NullPointerException
    java.lang.NoClassDefFoundError: radss/imageFile

    I'm assuming there is something more that I must do to import and use packages? Something else I need to define when making that class?

    As far as your second question, I am not sure what you are asking.

    My main applet is temp.java and the class that I made is imageFile.java. Do I need to have temp.class and imageFile.class both in the same directory as the web page? Thats the way i currently have it. Do I need to make a folder for the package. Such as have temp.class in one directory, and make a directory with it for radss (the package name) and put the imageFile.class in there.

    Thanks for your help ...
    Jerod Brown

  4. #4
    Join Date
    Mar 2003
    Posts
    834
    In not sure if it's creating packages or using them that you don't understand, so I'll walk you through an example.

    1. Create a new folder called "test"

    2. Create in that folder a file called "Test.html":
    Code:
    <html>
    	<body>
    		<applet height="50", width="300" code="MainAppletFile.class">
    		</applet>
    	</body>
    </html>
    3. Create in that folder a file called "MainAppletFile.java":
    Code:
    import java.applet.Applet;
    import java.awt.Graphics;
    import net.trycatch.applet.FileInPackage;
    
    public class MainAppletFile extends Applet {
    	public void paint(Graphics g) {
    		FileInPackage fip = new FileInPackage("Hello World from inside a package!");
    		g.drawString(fip.getMessage(), 50, 25);
    	}
    }
    As you can see, we're using a class called "FileInPackage". We haven't created that yet...but here it comes....

    4. Create a new folder in "test" called "net".

    5. Create a new folder in "net" called "trycatch".

    6. Create a new folder in "trycatch" called "applet"

    7. Create a new file in "applet" called "FileInPackage.java":
    Code:
    package net.trycatch.applet;
    
    public class FileInPackage {
    
    	private String msg;
    
    	public FileInPackage(String msg) {
    		this.msg = msg;
    	}
    
    	public String getMessage() {
    		return this.msg;
    	}
    }
    8. Compile "FileInPackage.java".

    9. Move back to the "test" folder and compile "MainAppletFile.java".

    10. Open "Test.html" in your browser. You should see "Hello World from inside a package!".

    OK. There are the steps, now a little word about what we've done.

    We created an HTML file and referred to a file called "MainAppletFile.class" which is our main applet file. This file refers to a class called "net.trycatch.applet.FileInPackage". We therefore created a package hierarchy for the class (as you do when creating a package) and the class itself.

    Hope this helps.
    ArchAngel.
    O:-)

  5. #5
    Join Date
    Sep 2003
    Posts
    16
    Thanks Archangel.

    I was creating the package right (hence no compile errors), but I simply wasn't placing the other .class file in the appropiate spot on the server. Thanks again, and I'm sure I'll bug you some more.
    Jerod Brown

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links