File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes getCodeBase ALT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "getCodeBase ALT?" Watch "getCodeBase ALT?" New topic
Author

getCodeBase ALT?

Konstantin Andry
Greenhorn

Joined: Apr 27, 2009
Posts: 9
Hello.

How to know in wich directory or site URL started my applet code if my applet do not created?
This information i need for create applet, and getCodeBase get Exception when I try to use this function after applet anitialized.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41125
    
  45
What do you mean by "my applet do not created"? If the applet is not being created, then there should be an error message in the Java Console that you can use for troubleshooting.

If the applet is in fact being created, and the call to getCodeBase results in an exception, then post the exception in full. Also post the complete applet tag and the directory structure on the server.


Ping & DNS - my free Android networking tools app
Konstantin Andry
Greenhorn

Joined: Apr 27, 2009
Posts: 9
Ulf Dittmer wrote:What do you mean by "my applet do not created"? If the applet is not being created, then there should be an error message in the Java Console that you can use for troubleshooting.

If the applet is in fact being created, and the call to getCodeBase results in an exception, then post the exception in full. Also post the complete applet tag and the directory structure on the server.


Creating the Applet code:

_Applet = new Main(); *
_Applet.start();

*In Main() constructor I try to resolve getCodeBase() function, but i get an Exception.
I think exception exists becose applet do not started when I do this.

That is why I need alternative way to get directory where my applet code was started...
Konstantin Andry
Greenhorn

Joined: Apr 27, 2009
Posts: 9
This is exception: Error while getCodeBase(): java.lang.NullPointerException



Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Applets are intended to be created by a Web browser, not from an application this way. The getCodeBase() method forwards to a similarly named method in the java.applet.AppletStub class. When the browser creates an instance of your applet, it calls setStub() and passes an instance of that browser's internal AppletStub subclass. It's up to that internal (ile., non-public) subclass of AppletStub to provide the codebase.

If you're doing something special where you host applets in an application -- i.e. if you're writing your own web browser -- then you have to this same thing. Write your own subclass of AppletStub, and use setStub() to tell the applet about it.

If, on the other hand, you're just kind of confused, and are including an applet in your Swing application for no particular reason, then just don't do that! Applets are intended for embedding in web pages, not for command-line use.


[Jess in Action][AskingGoodQuestions]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41125
    
  45
As a rule of thumb, whenever you have a constructor in an applet class, chances are you're doing something wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getCodeBase ALT?
 
Similar Threads
applet in jar does not work
Icons not visible in applet
Add music to applet?
how can i get path of class file in an app.?
images in JList