I am trying to make a jar file for handle webcam. I have to use this jar to another application. But this application made by java 1.6 so I have to convert this jar to 1.6. this code is ok for java 8. when I am trying to compile it by java 1.6 it given this this error
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
Please hep me how can i run this project by java 1.6
This is the code for capture image
public class CaptureImageMP extends 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();
}
this is the code for capture image and on/off camera UI
@SuppressWarnings("serial") public class TakeSnapshotFromVideoExample extends 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();
}
Note: i am using Netbeans IDE
Well, the library requires that you compiled the classes in JDK 1.6 or to version 1.6
At compile time, use source and target versions as below. Let me know if it works.
javac -source 1.6 -target 1.6