2011-09-27 100 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文件我得到它解決

相關問題