JNLP - java.lang.IllegalArgumentException:jnlp不是可缓存的资源

时间:2014-01-17 16:04:54

标签: java java-web-start jnlp

一旦我尝试运行该程序,我就会收到此错误。我不知道它可能意味着什么。 Janela没有显示任何错误,我从Deitel的书中拿到了这个程序。

java.lang.IllegalArgumentException: file:/home/eduardo/workspace/LogoAnimatorPanel/WebContent/animator.jnlp is not a cacheable resource
at net.sourceforge.jnlp.cache.CacheUtil.getCacheFile(CacheUtil.java:329)
at net.sourceforge.jnlp.util.XDesktopEntry.getContentsAsReader(XDesktopEntry.java:86)
at net.sourceforge.jnlp.util.XDesktopEntry.installDesktopLauncher(XDesktopEntry.java:181)
at net.sourceforge.jnlp.util.XDesktopEntry.createDesktopShortcut(XDesktopEntry.java:156)
at net.sourceforge.jnlp.runtime.ApplicationInstance.addMenuAndDesktopEntries(ApplicationInstance.java:159)
at net.sourceforge.jnlp.runtime.ApplicationInstance.initialize(ApplicationInstance.java:140)
at net.sourceforge.jnlp.Launcher.launchApplication(Launcher.java:514)
at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:917)

JaNeLA没有为animator.jnlp显示任何错误:

<?xml version="1.0" encoding="utf-8"?>
<jnlp
  spec="6.0+"
  codebase="file:/home/eduardo/workspace/LogoAnimatorPanel/WebContent/"
  href="animator.jnlp">
  <information>
    <title>Logo Animator Application</title>
    <vendor>Oracle Inc.</vendor>
    <homepage href="animator.html"/>
    <description>Logo Animator Application</description>
    <description kind="short">A demo of the capabilities 
      of the Logo Animator Application.</description>
    <offline-allowed/>  
  <shortcut online="true">
    <desktop/>
  </shortcut>
</information> 
<resources>
   <j2se version="1.6+" java-vm-args="-esa -Xnoclassgc"/>
   <jar href="../src/logoanimator/animator.jar" part="animator" 
   main="true" download="eager"/>                                                                                    
   <jar href="../src/logoanimator/jnlp.jar" part="animator" download="eager"/>
</resources>
  <application-desc main-class="logoanimator.MainAnimatorFrame"/>
 </jnlp> 

程序如下:

package logoanimator;

import java.awt.Dimension;
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.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

public class LogoAnimatorPanel extends JPanel {

protected ImageIcon images[];
private int currentImage = 0;
private final int ANIMATION_DELAY = 50;
private int width;
private int height;

private Timer animationTimer; 

public LogoAnimatorPanel() {
    try {
        FileOpenService fileOpenService = (FileOpenService) ServiceManager
                .lookup("javax.jnlp.FileOpenService");
        FileContents[] contents = fileOpenService.openMultiFileDialog(null,
                null);
        images = new ImageIcon[contents.length];
        for (int count = 0; count < images.length; count++) {
            byte[] imageData = new byte[(int) contents[count].getLength()];
            contents[count].getInputStream().read(imageData);
            images[count] = new ImageIcon(imageData);
        } 
        width = images[0].getIconWidth();
        height = images[0].getIconHeight(); 
    } 
    catch (Exception e) {
        e.printStackTrace();
    } 
} 


public void paintComponent(Graphics g) {
    super.paintComponent(g); 
    images[currentImage].paintIcon(this, g, 0, 0);
    if (animationTimer.isRunning())
        currentImage = (currentImage + 1) % images.length;
} 

public void startAnimation()
{
   if(animationTimer == null)
   {
      currentImage = 0; 
      animationTimer = new Timer(ANIMATION_DELAY, new TimerHandler());
      animationTimer.start();   
   } 
   else 
   {
      if (! animationTimer.isRunning())
         animationTimer.restart();
   } 
} 
public void stopAnimation()
{
    animationTimer.stop();
} 
public Dimension getMinimumSize()
{
   return getPreferredSize();
} 
public Dimension getPreferredSize()
{
   return new Dimension( width, height );
} 
private class TimerHandler implements ActionListener
{
   public void actionPerformed( ActionEvent actionEvent )
   {
      repaint(); 
   } 
} 
 } 

package logoanimator;

import javax.swing.JFrame;

public class MainAnimatorFrame {
     public static void main(String[] args) {

    LogoAnimatorPanel animation = new LogoAnimatorPanel();
    JFrame animatorFrame = new JFrame("Animator Frame");
    animatorFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    animatorFrame.add(animation);
    animatorFrame.pack();
    animatorFrame.setVisible(true);
    animation.startAnimation();
}
}

0 个答案:

没有答案