javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Hello,
I'm using NetBeans 7.2.1 with JDK 1.6 in a Windows XP system.
I have a problem with an Applet during runtime. The problem used to appear during compilation, but I found that adding the classpaths javaws.jar and jnlp.jar sorta solve the problem. Also, enabling Webstart and using it as a set configuration helped.
Again, the program compiles fine, but the problem arises during runtime. The program is supposed to ask the user for an image file in the local machine, but it doesn't do so.
The whole description of the problem:
compile-single:
run-applet:
javax.jnlp.UnavailableServiceException: uninitialized
at javax.jnlp.ServiceManager.lookup(ServiceManager.ja va:44)
at org.me.hello.ImageScale.init(ImageScale.java:63)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
BUILD SUCCESSFUL (total time: 12 seconds)
My code:
Code :
package org.me.hello;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.jnlp.FileContents;
import javax.jnlp.FileOpenService;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ImageScale extends JApplet
{
private ImageIcon image;
private JPanel scaleJPanel;
private JLabel percentJLabel;
private JTextField scaleInputJTextField;
private JButton scaleChangeJButton;
private double scaleValue=1.0;
@Override
public void init()
{
scaleJPanel=new JPanel();
percentJLabel=new JLabel("scale percent:");
scaleInputJTextField=new JTextField("100");
scaleChangeJButton=new JButton("Set Scale");
scaleJPanel.add(percentJLabel);
scaleJPanel.add(scaleInputJTextField );
scaleJPanel.add(scaleChangeJButton);
add(scaleJPanel, BorderLayout.NORTH );
scaleChangeJButton.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
scaleValue=Double.parseDouble( scaleInputJTextField.getText() ) /100.0;
repaint();
}
}
);
try
{
FileOpenService fileOpenService =
(FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService");
FileContents contents= fileOpenService.openFileDialog(null, null);
byte[] imageData=new byte[ (int ) contents.getLength() ];
contents.getInputStream().read( imageData);
image=new ImageIcon( imageData);
add( new DrawJPanel(), BorderLayout.CENTER);
}
catch(Exception e)
{
e.printStackTrace();
}
}
private class DrawJPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
double spareWidth=
getWidth()-scaleValue* image.getIconWidth();
double spareHeight=
getHeight()-scaleValue*image.getIconHeight();
g.drawImage( image.getImage(),
(int) (spareWidth)/2, (int)(spareHeight)/2,
(int)(image.getIconWidth() *scaleValue),
(int)(image.getIconHeight()*scaleValue ), this);
}
}
}
Thank you.
Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Here's your problem, lines 62-63:
FileOpenService fileOpenService = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService" );
javax.jnlp
I'm guessing you imported it correctly. Maybe that'll help. If you still can't figure it out, I might search for the answer.
Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Quote:
Originally Posted by
Programming_Hobbyist
Here's your problem, lines 62-63:
FileOpenService fileOpenService = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService" );
javax.jnlp
I'm guessing you imported it correctly. Maybe that'll help. If you still can't figure it out, I might search for the answer.
I don't know why you call those lines a problem, when the code is written exactly as your "correction".
Also, I added the class path of jnlp.jar and javaws.jar, but I don' know what you mean by importing something. All the import statements are written on the top of the code.
I have read many websites, but all of them take for granted that the code should run with all the specifications that I mentioned on my posts.
Nevertheless, thank you for your help so far and all of the ones who have at least given a look at my post.
Additional information: The errors during run-time most likely do not allow the applet to ask for a file to search in the local machine. So, even with errors the applet runs, but I am unable to select an image file to scale it. The applet would appear without an image to scale.
Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Could someone help or give me an idea? It would even help, if you can recommend another programming software where Applets can actually work. I have tried Eclipse and NetBeans and both give me trouble.
Thank you.
Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)
Search for your error message. From what I have seen in search results more than one problem can cause the symptoms you see here, but the most popular solution I found was people reporting that the installation of webstart was incorrect, and a couple said that restarting their IDE fixed it while others had to follow other steps (which I did not read).
I don't know what the problem is, sorry. But I think a search engine and some effort may give you clues that will lead to a solution.
Quote:
I have tried Eclipse and NetBeans and both give me trouble.
They give everyone trouble. You can always use vi or something.