如何在运行通过JNLP启动的applet时解决“AWT-EventQueue-0”异常

时间:2012-08-29 11:23:02

标签: java awt jnlp

我正在通过JNLP运行applet时获得Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

我的小程序代码是

package com.oprs.common;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;

import javax.jnlp.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.jfree.util.Log;
/**
 *
 * @date Aug 29, 2012 11:33:16 AM
 * @version 1.0
 */
public class OprsJNLP {

    /**
     * @param args
     */
    static BasicService basicService = null;

    public static void main(String[] args) {
    JFrame frame = new JFrame("OPRS");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel();
    Container content = frame.getContentPane();
    content.add(label,BorderLayout.CENTER);
    String message = "Download OPRS Application";
    label.setText(message);

    try {
        basicService = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
    } catch (UnavailableServiceException e) {
        Log.error("service not available", e);
    }

    JButton button = new JButton("http://google.com/");

    ActionListener listener = new ActionListener() {

        public void actionPerformed(ActionEvent event) {
        URL url;
        try {
            url = new URL(event.getActionCommand());
            basicService.showDocument(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }       
        }
    };

    button.addActionListener(listener);

    content.add(button, BorderLayout.SOUTH);
    frame.pack();
    frame.show();
    }
}

我尝试调试并发现basicService始终返回null。取代google.com我尝试了其他网址,但仍然得到相同的错误。行basicService.showDocument(url);是抛出空指针的地方,因为我的basicService为null。有人可以指出我错在哪里吗?

包括我的.jnlp

<?xml version='1.0' encoding='UTF-8' ?>
<jnlp spec='1.0'
      codebase='http://localhost:9999/'
      href='oprs.jnlp'>
  <information>
    <title>OPRS</title>
    <vendor>OPRS</vendor>
    <description kind='one-line'>
      OPRS WEB START
    </description>
    <shortcut online='false'>
      <desktop/>
    </shortcut>
  </information>
  <resources>
    <j2se version='1.4+' />
    <jar href='oprs.jar' main='true' />
  </resources>
  <application-desc main-class='com.oprs.OprsJNLP' />
</jnlp>

0 个答案:

没有答案
相关问题