这是一个applet小程序:
import java.awt.*;
import java.net.*;
import java.applet.*;
public class Applet11 extends Applet {
URL url1;
Image image1;
public void init() { url1= new URL("file:/e:/pic/1.jpg");
image1=getImage(url1);
}
public void paint(Graphics g) {
g.drawImage(image1,0,120,100,100,this);
}
}
编译时总是报这样的错误:
Applet11.java:10: unreported exception java.net.MalformedURLException; must be caught or declared to be thrownurl1= new URL("file:///d://Snap1.bmp");^1 error不知怎么解决,希望指导一下,谢谢了
import java.awt.*;
import java.net.*;
import java.applet.*;
public class Applet11 extends Applet {
URL url1;
Image image1;
public void init() { url1= new URL("file:/e:/pic/1.jpg");
image1=getImage(url1);
}
public void paint(Graphics g) {
g.drawImage(image1,0,120,100,100,this);
}
}
编译时总是报这样的错误:
Applet11.java:10: unreported exception java.net.MalformedURLException; must be caught or declared to be thrownurl1= new URL("file:///d://Snap1.bmp");^1 error不知怎么解决,希望指导一下,谢谢了
url1= new URL("file:/e:/pic/1.jpg");
^
新的程序是这样的:
import java.awt.*;
import java.net.*;
import java.applet.*;
public class Applet11 extends Applet {
URL url1;
Image image1;
public void init() {
try{
url1 = new URL("file:/e:/pic/1.jpg");
image1 = getImage(url1);
}
catch(java.net.MalformedURLException e){
System.out.println("Unreported exception: " + e.getMessage());
}
}
public void paint(Graphics g) {
g.drawImage(image1,0,120,100,100,this);
}
}
我有运行过
从报错信息来看url1= new URL("file:/e:/pic/1.jpg");
查一下是否你的pc是否有file:/e:/pic/1.jpg?