0

I am getting Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException while running applet launched via JNLP.

My applet code is

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();
    }
}

I tried to debug and found that basicService is returning null always. In place of google.com i tried with the other url's but still getting the same error. The line basicService.showDocument(url); is where it throws null pointer because my basicService is null. Can some one point out where exactly i am going wrong ?

Including my .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>
Srikanth Sridhar
  • 2,317
  • 7
  • 30
  • 50
  • 1
    Are you sure you don't have _service not available_ in your log file ? – Istao Aug 29 '12 at 12:13
  • Hi, thanks for replying. Sorry i din't check the logs. I am having service not available in logs. can you please guide me in resolving it. – Srikanth Sridhar Aug 29 '12 at 12:22
  • Why do you keep mentioning 'applet' when the code is not an applet? What is the content of the JNLP (paste it as an edit to the question)? How ***exactly*** is the app. being launched (e.g. the command typed on the CLI or the menu items chosen in an IDE)? – Andrew Thompson Aug 29 '12 at 12:39
  • 1
    `frame.show();` Don't ignore deprecation warnings. Fix them. – Andrew Thompson Aug 29 '12 at 12:40
  • @ Andrew Thompson, you are right, i changed this to `frame.setVisible(true)`, but still the same erroe message. – Srikanth Sridhar Aug 29 '12 at 12:46
  • If there is *service not available* in your log, the service is not available :-) Do you run your "applet" from a browser ? Can you provide your jnlp file ? – Istao Aug 29 '12 at 14:07
  • @ Isato, yes i do run my applet from browser. I have included my jnlp file – Srikanth Sridhar Aug 30 '12 at 06:06

0 Answers0