开发者

Exception in thread AWT-EventQueue-2 java.lang.NullPointerException

开发者 https://www.devze.com 2023-04-07 15:34 出处:网络
I am trying to run a JApplet with jnlp. I have created my MyApplet which extends JApplet and packaged in a jar.

I am trying to run a JApplet with jnlp. I have created my MyApplet which extends JApplet and packaged in a jar. I have also created MyApplet.jnlp and MyApplet.html My Runtime env is jdk 1.7.0.02.

When I run it in a browser I get below exception from the browser, but my applet is running properly from the eclipse as a stand alone

This is the exception I am getting

Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
            at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$8.run(Unknown Source)
            at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDT(Unknown Source)
            at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.resize(Unknown Source)

Please find my code below. This is the applet class which is running fine through Eclipse:

        import java.awt.Color;
        import java.awt.开发者_JS百科Container;
        import java.awt.Graphics;

        import javax.swing.JApplet;
        //This is my applet class
        public class MyApplet extends JApplet {

            private Container Panel;
        //constructor
              public MyApplet () {
                super ();
                Panel = getContentPane();
                Panel.setBackground (Color.cyan);
              }

    //paint method
              public void paint (Graphics g) {
                int Width;
                int Height;

                super.paint (g);
                Width = getWidth();
                Height = getHeight();
                g.drawString ("The applet width is " + Width + " Pixels", 10, 30);
                g.drawString ("The applet height is " + Height + " Pixels", 10, 50);
              }

        }

This is the html file, MyApplet.html:

                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <html lang="en-US">
                  <head>
                    <title>My Applet Menu Chooser Applet</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
                  </head>
                  <body>
                    <noscript>A browser with JavaScript enabled is required for this page to operate properly.</noscript>
                    <h1>Draggable Menu ChooserApplet</h1>
                    <p>Press the <b>Left</b> button on your mouse and drag the applet.</p>


                    <script src="http://www.java.com/js/deployJava.js"></script>
                    <script>
                        var attributes = { code:'MyApplet', width:900, height:300 };
                        var parameters = {jnlp_href: 'MyApplet.jnlp', draggable: 'true'} ;
                        deployJava.runApplet(attributes, parameters, '1.6');
                    </script>
                  </body>
                </html>

MyAppletJnlp.jnlp

                <?xml version="1.0" encoding="utf-8"?> 
                <jnlp spec="1.0+"  href="MyApplet.jnlp">
                    <information>
                        <title>Jnlp Testing</title>
                        <vendor>akash sharma</vendor>
                        <description>Testing Testing</description>
                         <offline-allowed />
                        <shortcut online="false">
                            <desktop />
                        </shortcut>
                    </information>

                    <security>
                        <all-permissions/>
                    </security>
                    <resources>
                        <!-- Application Resources -->

                              href="http://java.sun.com/products/autodl/j2se"/>
                        <jar href="MyApplet.jar" main="true" />
                    </resources>
                    <applet-desc 
                         name="Draggable Applet"
                         main-class="com.acc.MyApplet"
                         width="900"
                         height="300">
                     </applet-desc>
                     <update check="background"/>

                </jnlp>


I got the solution. Actually In the jar file the path of the class file was not correct that which I have mentioned in the JNLP file that is why I was getting null pointer exception.Once i updated the jar files i got it resolved

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号