我正在尝试为手柄网络摄像头制作一个 jar 文件。我必须将此 jar 用于另一个应用程序。但是这个应用程序是由 java 1.6 制作的,所以我必须把这个 jar 转换为 1.6。这段代码适用于 java 8。当我试图用 java 1.6 编译它时,它给出了这个错误
Updating property file: F:\Core Java\Camera\build\built-jar.properties
Compiling 1 source file to F:\Core Java\Camera\build\classes
compile-single:
run-single:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/github/sarxos/webcam/WebcamPanel : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at ati.com.camera.CaptureImageMP.main(CaptureImageMP.java:53)
Java Result: 1
请帮助我如何通过 java 1.6 运行这个项目
这是捕获图像的代码
公共类 CaptureImageMP 扩展 VBean {
private IHandler mHandler;
private Main formsMain;
protected static final ID VN_NO = ID.registerProperty("VN_NO");
@Override
public void init(IHandler handler) {
mHandler = handler;
super.init(handler);
formsMain = (Main) mHandler.getApplet();
}
@Override
public boolean setProperty(ID _ID, Object _args) {
System.out.println("Method Called");
if (_ID == VN_NO) {
System.out.println("Got VN No" + VN_NO);
System.out.println("Got _ID No" + _ID);
if (_args != null) {
System.out.println("Got parameter :" + _args);
try {
new TakeSnapshotFromVideoExample();
} catch (Exception ex) {
System.out.println("Exception: " + ex);
return false;
}
}
return true;
}
//return true;
return super.setProperty(_ID, _args);
}
public static void main(String[] args) throws InterruptedException {
new TakeSnapshotFromVideoExample();
// Thread.sleep(1000);
// new Game1();
}
这是捕获图像和开/关相机 UI 的代码
@SuppressWarnings("serial") 公共类 TakeSnapshotFromVideoExample 扩展 JFrame {
private class SnapMeAction extends AbstractAction {
public SnapMeAction() {
super("Snapshot");
}
@Override
public void actionPerformed(ActionEvent e) {
// int unique_id= (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
int unique_id= (int) (Integer.MAX_VALUE);
try {
for (int i = 0; i < webcams.size(); i++) {
Webcam webcam = webcams.get(i);
//File file = new File(String.format("Image\\"+unique_id+".jpg", i));
File file = new File(String.format("F:\\Core Java\\camera\\ATILimitedRegImage\\"+unique_id+".jpg", i));
ImageIO.write(webcam.getImage(), "JPG", file);
System.out.format("Image for %s saved in %s \n", webcam.getName(), file);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
private class StartAction extends AbstractAction implements Runnable {
public StartAction() {
super("Start");
}
@Override
public void actionPerformed(ActionEvent e) {
btStart.setEnabled(false);
btSnapMe.setEnabled(true);
// remember to start panel asynchronously - otherwise GUI will be
// blocked while OS is opening webcam HW (will have to wait for
// webcam to be ready) and this causes GUI to hang, stop responding
// and repainting
executor.execute(this);
}
@Override
public void run() {
btStop.setEnabled(true);
for (WebcamPanel panel : panels) {
panel.start();
}
}
}
private class StopAction extends AbstractAction {
public StopAction() {
super("Stop");
}
@Override
public void actionPerformed(ActionEvent e) {
btStart.setEnabled(true);
btSnapMe.setEnabled(false);
btStop.setEnabled(false);
for (WebcamPanel panel : panels) {
panel.stop();
}
}
}
private Executor executor = Executors.newSingleThreadExecutor();
//private Dimension size = WebcamResolution.QQVGA.getSize();
private Dimension size = WebcamResolution.VGA.getSize();
private List<Webcam> webcams = Webcam.getWebcams();
private List<WebcamPanel> panels = new ArrayList<WebcamPanel>();
private JButton btSnapMe = new JButton(new SnapMeAction());
private JButton btStart = new JButton(new StartAction());
private JButton btStop = new JButton(new StopAction());
public TakeSnapshotFromVideoExample() {
super("Test Snap Different Size");
for (Webcam webcam : webcams) {
webcam.setViewSize(size);
WebcamPanel panel = new WebcamPanel(webcam, size, false);
//panel.setFPSDisplayed(true);
panel.setFillArea(true);
panels.add(panel);
}
// start application with disable snapshot button - we enable it when
// webcam is started
btSnapMe.setEnabled(false);
btStop.setEnabled(false);
setLayout(new FlowLayout());
for (WebcamPanel panel : panels) {
add(panel);
}
add(btSnapMe);
add(btStart);
add(btStop);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TakeSnapshotFromVideoExample();
}
注意:我正在使用 Netbeans IDE