我正在解决我的代码中的问题,这个实验室会显示来自网址的图片,但不断收到输出:“哦,哦,发生了一些不好的事情。”来自catch块中的给定代码
我一直在寻找如何解决网址问题,我尝试重新输入双引号和http://并在浏览器中运行网址没有任何问题。我似乎无法弄明白我从
获得例外的地方这些方法由教授
提供文件名http://venus.cs.qc.cuny.edu/~aabreu/cs212/images/
这是调用URL的代码
public void loadImages() {
Document doc;
String url = "http://venus.cs.qc.cuny.edu/~aabreu/cs212/images/";
int j = 0;
try {
System.out.println("Reading URL directory");
doc = Jsoup.connect(url).get();
Elements files = doc.getElementsByTag("a");
// initialize the array size for the filenames
picture = new String[files.size()];
for (Element file : files) {
String filename = file.attr("href");
if (filename.indexOf(".jpg") >= 0 || filename.indexOf(".gif") >= 0) {
System.out.println(filename);
picture[j++] = url + filename;
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
* /
public synchronized void drawPict(String fileName) {
try {
System.out.println(fileName); // FileName is a local file
// ImageIcon imgIcon = new ImageIcon(this.getClass().getResource(fileName)); //
// FileName is an URL
ImageIcon imgIcon = new ImageIcon(new URL(fileName));
pict = imgIcon.getImage();
if (pict != null) {
MediaTracker imageTracker = new MediaTracker(this);
imageTracker.addImage(pict, 0);
try {
imageTracker.waitForAll();
} catch (InterruptedException e) {
}
parent.setVisible(false);
this.setSize(pict.getWidth(this), pict.getHeight(this));
parent.setSize(pict.getWidth(this), pict.getHeight(this));
parent.setVisible(true);
repaint();
}
} catch (MalformedURLException mue) {
System.out.println("Oh oh, something bad happened");
}
}