0

我无法保存已加载的图片。图片保存在该程序所在的同一文件夹下。错误不断重复出现。错误画面如下

错误

---------- Capture Output ----------
>"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" loadapicture
java.lang.NoClassDefFoundError: loadapicture
Caused by: java.lang.ClassNotFoundException: loadapicture
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: loadapicture.  Program will exit.
Exception in thread "main" 
> Terminated with exit code 1.

我的程序

import hsa.*;
import java.awt.*;
// Look at all of these extra imports needed for a picture file
import java.io.File;
import java.io.IOException;
import java.awt.image.*;
import javax.imageio.*;


public class loadapicture{
    public static void main(String[] args){
        Console con = new Console();

        // Variables need to open a picture file
        File tictactoefile;
        BufferedImage tictactoeimage;
        tictactoefile = null;
        tictactoeimage = null;

        // Now that the variables are created.. Time to load the picture into the variables
        // BTW  You need to load the file using a block called try/catch
        // Becuase if the file does not exist, you need to catch the error
        // You can use jpg, gif, and bmp

        try{
            // Trying to open the file and loading it
            tictactoefile = new File("");
            tictactoeimage = ImageIO.read( owin.jpeg);

        }catch(IOException e){
            // If the file is not found, this will happen
            con.println("ERROR... IMAGE FILE NOT FOUND"); 
        }


        con.drawImage(tictactoeimage, 100, 100, null);

        // Yes you can do all of this in a method
}
}

如何正确下载和保存图像?

4

1 回答 1

2

我想你只需要指定你的班级的路径

"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" -classpath <path to your class> loadapicture
于 2012-04-24T14:49:28.393 回答