草庐IT

java - 打开 JFileChooser 时出现 IOException

coder 2024-03-21 原文

好吧,这个真的很奇怪。每次我的应用程序第一次打开 JFileChooser 时,它都会抛出 IOException,然后某些图标无法正确显示。

java.io.IOException
    at sun.awt.image.GifImageDecoder.readHeader(GifImageDecoder.java:265)
    at sun.awt.image.GifImageDecoder.produceImage(GifImageDecoder.java:102)
    at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)

现在,当我深入研究错误时,似乎在一个图标上,当它试图读取 header 时,它只检索前 8 个字节,这是不够的。我已经检查了图标文件,它们看起来都不错。 我试图用另一个在此错误之前正确加载的图标文件覆盖图标文件,但同样的事情。

这是我遇到这个错误时的堆栈:

Daemon Thread [Image Fetcher 0] (Suspended (exception IOException)) 
    GifImageDecoder.readHeader() line: 265 [local variables unavailable]    
    GifImageDecoder.produceImage() line: 102 [local variables unavailable]  
    ByteArrayImageSource(InputStreamImageSource).doFetch() line: 246    
    ImageFetcher.fetchloop() line: 172  
    ImageFetcher.run() line: 136 [local variables unavailable]

这是我深入研究 GifImageDecoder 实例时的变量值。

source  ByteArrayImageSource  (id=272)  
awaitingFetch   false   
consumers   null    
decoder GifImageDecoder  (id=271)   
decoders    GifImageDecoder  (id=271)   
imagedata    (id=307)   
    [0] 71  
    [1] 73  
    [2] 70  
    [3] 56  
    [4] 57  
    [5] 97  
    [6] 16  
    [7] 13  
    [8] 10  
imagelength 9   
imageoffset 0   

通常,这个图像数据应该大得多。前 10 个字节是 header ,但如您所见,它只检索 8 个字节。在此异常之后,JFileChooser 中的所有其他图标都无法正确加载。

这是对 readHeader() 的正确调用:

source  ByteArrayImageSource  (id=208)  
awaitingFetch   false   
consumers   null    
decoder GifImageDecoder  (id=207)   
decoders    GifImageDecoder  (id=207)   
imagedata    (id=223)   
    [0...99]    
    [100...199] 
    [200...299] 
    [300...399] 
    [400...499] 
    [500...599] 
    [600...699] 
    [700...799] 
    [800...899] 
    [900...979] 
imagelength 980 
imageoffset 0   

缓冲区已完全加载,并且在引发错误的图标之前有一个图标。

这是一个可能崩溃的例子(它发生在我的代码的几个部分,每当我第一次加载我的系统图标时):

public class DirectoryBrowser extends JFileChooser{

private String suffixAccepted = null;

public DirectoryBrowser(File file, String chooserTitle, String approveOpenBtnText, String suffixAccepted)
{
    super(file);
    this.suffixAccepted = suffixAccepted;
    init(chooserTitle, approveOpenBtnText);
}

当它进入 super (文件)时,它会去那里:

Thread [AWT-EventQueue-0] (Suspended)   
    Object.wait(long) line: not available [native method]   
    MediaTracker.waitForID(int, long) line: 651 
    ImageIcon.loadImage(Image) line: 234    
    ImageIcon.<init>(byte[]) line: 215  
    SwingUtilities2$2.createValue(UIDefaults) line: 1105    
    UIDefaults.getFromHashtable(Object) line: 185   
    UIDefaults.get(Object) line: 130    
    MultiUIDefaults.get(Object) line: 44    
    MultiUIDefaults(UIDefaults).getIcon(Object) line: 411   
    UIManager.getIcon(Object) line: 613 
    IronFileChooserUI(BasicFileChooserUI).installIcons(JFileChooser) line: 233  
    IronFileChooserUI(BasicFileChooserUI).installDefaults(JFileChooser) line: 219   
    IronFileChooserUI(BasicFileChooserUI).installUI(JComponent) line: 135   
    IronFileChooserUI(MetalFileChooserUI).installUI(JComponent) line: 139   
    DirectoryBrowser(JComponent).setUI(ComponentUI) line: 653   
    DirectoryBrowser(JFileChooser).updateUI() line: 1757    
    DirectoryBrowser(JFileChooser).setup(FileSystemView) line: 366  
    DirectoryBrowser(JFileChooser).<init>(File, FileSystemView) line: 332   
    DirectoryBrowser(JFileChooser).<init>(File) line: 315   
    DirectoryBrowser.<init>(File, String, String, String) line: 33  
    PackToIntegratePanel.choosePackPathToIntegrateFile() line: 522  
    PackToIntegratePanel$1.actionPerformed(ActionEvent) line: 104   
    JButton(AbstractButton).fireActionPerformed(ActionEvent) line: 1849 
    AbstractButton$Handler.actionPerformed(ActionEvent) line: 2169  
    DefaultButtonModel.fireActionPerformed(ActionEvent) line: 420   
    DefaultButtonModel.setPressed(boolean) line: 258    
    BasicButtonListener.mouseReleased(MouseEvent) line: 236 
    JButton(Component).processMouseEvent(MouseEvent) line: 5517 
    JButton(JComponent).processMouseEvent(MouseEvent) line: 3135    
    JButton(Component).processEvent(AWTEvent) line: 5282    
    JButton(Container).processEvent(AWTEvent) line: 1966    
    JButton(Component).dispatchEventImpl(AWTEvent) line: 3984   
    JButton(Container).dispatchEventImpl(AWTEvent) line: 2024   
    JButton(Component).dispatchEvent(AWTEvent) line: 3819   
    LightweightDispatcher.retargetMouseEvent(Component, int, MouseEvent) line: 4212 
    LightweightDispatcher.processMouseEvent(MouseEvent) line: 3892  
    LightweightDispatcher.dispatchEvent(AWTEvent) line: 3822    
    WorkbenchFrame(Container).dispatchEventImpl(AWTEvent) line: 2010    
    WorkbenchFrame(Window).dispatchEventImpl(AWTEvent) line: 1791   
    WorkbenchFrame(Component).dispatchEvent(AWTEvent) line: 3819    
    EventQueue.dispatchEvent(AWTEvent) line: 463    
    EventDispatchThread.pumpOneEventForHierarchy(int, Component) line: 242  
    EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 163   
    EventDispatchThread.pumpEvents(int, Conditional) line: 157  
    EventDispatchThread.pumpEvents(Conditional) line: 149   
    EventDispatchThread.run() line: 110 

然后上面提到的其他线程检索图标(参见本文的第二个堆栈)

最佳答案

What do you mean? I don't manipulate any queue.

对不起。就像@kai 说的,我的意思是 event dispatch thread (EDT) .确保在 EDT 上创建所有您的组件,包括 JFileChooser,就像它们在 tutorial 中显示的那样.如果你不这样做,这将是一些文件系统和你的显示器之间的竞争。

我刚注意到:如果没有 IronFileChooser 东西,它还会发生吗?

关于java - 打开 JFileChooser 时出现 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7913270/

有关java - 打开 JFileChooser 时出现 IOException的更多相关文章

  1. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  2. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  3. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  4. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  5. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  6. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  7. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  8. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  9. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  10. 【Java 面试合集】HashMap中为什么引入红黑树,而不是AVL树呢 - 2

    HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候

随机推荐