2011-09-27 50 views
0

我想用jnlp运行JApplet。 我创建了我的MyApplet,它扩展了JApplet并打包在一个jar中。 我也创建了MyApplet.jnlp和MyApplet.html My Runtime env是jdk 1.7.0.02。线程异常AWT-EventQueue-2 java.lang.NullPointerException

当我在浏览器中,我得到从浏览器的异常以下运行它,但我的小程序正确地从Eclipse作为一个独立的

这个运行是我得到

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) 

异常请在下面找到我的代码。这是通过Eclipse的罚款运行Applet类:

 import java.awt.Color; 
     import java.awt.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); 
       } 

     } 

这是HTML文件,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> 
+0

我得到了解决方案 其实在jar文件类文件的路径是不正确的,这就是为什么我得到空指针exception.Once我更新了jar文件,我得到它解决 – Akash

回答

1

我得到了解决。其实在jar文件类文件的路径是不正确的,我已经在JNLP文件中提到,这就是为什么我得到空指针exception.Once我更新了jar文件我得到它解决

相关问题