Results 1 to 3 of 3
- 02-21-2011, 04:29 AM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
getCodeBase() in an application problem
Hey!
Been wrestling with this for a few hours, but have given up and figured might as well see what brighter minds can shed on this.
Basically, it's an applet that I have (after a lot of googling) converted to an application/applet... one problem is that because of GetCodeBase() it is throwing a nullpointerexception if run as an app. If you run the same thing as an Applet it works perfectly.
What to do?
Heres the code:
Java Code:import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import javax.swing.JApplet; import javax.swing.JFrame; import javax.swing.JLabel; public class TestSound6 extends Applet implements ActionListener{ public static void main(String[] args) { //... Create an initialize the applet. TestSound6 theApplet = new TestSound6(); theApplet.init(); // Needed if overridden in applet //theApplet.start(); // Needed if overridden in applet //... Create a window (JFrame) and make applet the content pane. JFrame window = new JFrame("Sample Applet and Application"); window.setContentPane(theApplet); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); // Arrange the components. //System.out.println(theApplet.getSize()); window.setVisible(true); // Make the window visible. } public TestSound6() { add(new JLabel("This is both an Applet and Application!")); } Button play,stop; AudioClip audioClip; public void init(){ play = new Button(" Play in Loop "); add(play); play.addActionListener(this); stop = new Button(" Stop "); add(stop); stop.addActionListener(this); audioClip = getAudioClip(getCodeBase(), "bark.wav"); } public void actionPerformed(ActionEvent ae){ Button source = (Button)ae.getSource(); if (source.getLabel() == " Play in Loop "){ audioClip.play(); } else if(source.getLabel() == " Stop "){ audioClip.stop(); } } }
- 02-21-2011, 07:47 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because that method is only applicable to Applets and the environment they run in.
Java Code:getClass().getProtectionDomain().getCodeSource()
- 02-21-2011, 03:38 PM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Similar Threads
-
problem in my application
By jperson in forum Advanced JavaReplies: 3Last Post: 01-06-2010, 03:48 PM -
URL Problem with IE7 in my struts Application
By SreenivasGurramkonda in forum Web FrameworksReplies: 0Last Post: 11-27-2008, 08:14 AM -
Problem In Web Application
By sharfi in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-16-2008, 10:36 AM -
problem locating file in web application
By Rem in forum New To JavaReplies: 0Last Post: 11-09-2007, 04:00 PM -
Help with method getCodeBase()
By fernando in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks