Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
    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.


  2. #2

    Default 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.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)

    Quote Originally Posted by Programming_Hobbyist View Post
    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.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javax.jnlp.UnavailableServiceException: uninitialized (PROBLEM AT RUNTIME)

    Anyone?

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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.


    I have tried Eclipse and NetBeans and both give me trouble.
    They give everyone trouble. You can always use vi or something.

Similar Threads

  1. noClassDefFoundError trying to run JNLP file with Web Start
    By sonicjr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2012, 12:43 AM
  2. Java and JNLP
    By parvendra in forum Java Theory & Questions
    Replies: 9
    Last Post: March 4th, 2011, 10:04 AM
  3. JNLP webstart application in localhost
    By Jhovarie in forum Threads
    Replies: 2
    Last Post: February 14th, 2011, 06:53 PM
  4. can't start jnlp file
    By NARs in forum Java Applets
    Replies: 1
    Last Post: December 1st, 2009, 03:25 AM
  5. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM