JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 [求助]關於applet的imageio.IIOException問題
butalpha





發文: 5
積分: 0
於 2006-07-27 23:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
寫了一個小程式碼,如下:
===============================================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
 
import rc.*;
 
public class EventTestRemoteC extends Applet implements ActionListener
{
  Button bu = new Button("。Open Remote Control。開啟遙控器。");
 
  public void init()  //applet初始化
  {
    add(bu); //將按鈕加入applet
    bu.addActionListener(this);  //按鈕加入傾聽
  }
  public void actionPerformed(ActionEvent e)
  {  
  showStatus("遙控器開啟中");
  
  RemoteCtrlFrame rcgo = new RemoteCtrlFrame();
  rcgo.start();
  }
}

===============================================
該檔案存於rc這個資料夾,另外還有RemoteCtrlPane.java檔,程式碼如下:

===============================================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
 
import javax.swing.*;
import javax.imageio.ImageIO.*;  //原本是import javax.imageio.ImageIO.read;  20060727 modify
 
import org.cybergarage.util.*;
 
public class RemoteCtrlPane extends JPanel implements MouseListener
{
  private final static int IMAGE_BORDER_SIZE = 20;
 
  public RemoteCtrlPane()
  {
    loadImage();
    initPanel();
    addMouseListener(this);
  }
 
  private RemoteCtrl tvDev = null;
  
  public void setDevice(RemoteCtrl dev)
  {  tvDev = dev;
  }
 
  public RemoteCtrl getDevice()
  {  return tvDev;
  }
  
  private final static String CLOCK_PANEL_IMAGE = "images/remotectrl.jpg";
 
  private BufferedImage panelmage;
  
  private void loadImage()
  {
    File f = new File(CLOCK_PANEL_IMAGE);
    try {  panelmage = javax.imageio.ImageIO.read(f);  //原本是panelmage=ImageIO.read(f);  20060727 修改,這裡是第64行,也就是錯誤的地方,但是不知道錯在何處。
    }
    catch (Exception e) 
                {  Debug.warning(e);
    }
  }
 
  private BufferedImage getPaneImage()
  {  return panelmage;
  }
 
  private void initPanel()
  {  BufferedImage panelmage = getPaneImage();
    setPreferredSize(new Dimension(panelmage.getWidth(), panelmage.getHeight()));
  }

(以下程式碼應該無關,省略。)
==============================================
執行EventTestRemoteC這個 applet 之後,JAVA主控台出現錯誤如下:

javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at RemoteCtrlPane.loadImage(RemoteCtrlPane.java:64)
at RemoteCtrlPane.<init>(RemoteCtrlPane.java:31)
at RemoteCtrlFrame.<init>(RemoteCtrlFrame.java:31)
at EventTestRemoteC.actionPerformed(EventTestRemoteC.java:20)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at RemoteCtrlPane.initPanel(RemoteCtrlPane.java:83)
at RemoteCtrlPane.<init>(RemoteCtrlPane.java:32)
at RemoteCtrlFrame.<init>(RemoteCtrlFrame.java:31)
at EventTestRemoteC.actionPerformed(EventTestRemoteC.java:20)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

圖檔我放在 rc/images/底下,在dos模式下執行 appletviewer 可以正常執行,用瀏覽器卻開不起來,依照JAVA主控台的錯誤訊息來看,是跟 image 的 IO 有關係,思考許久不知如何下手,因此來詢問各位大大,希望各位大大可以提供一些解決方案、告知小弟如何處理。麻煩撥空幫我解答,感激不盡!


Duncan edited on 2006-07-28 01:54
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2178 [求助]關於applet的imageio.IIOException問題 butalpha 4136 2006-07-27 23:57
1262 Re:[求助]關於applet的imageio.IIOException問題 Duncan 62 2006-07-28 01:55
» JWorld@TW »  Java SE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8