I am getting following error message when I run the HelloWorld.java example, out of JGraphX package, and move a cell by dragging and dropping it.
java.io.IOException: Data translation failed: not an image format
at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1293)
at sun.lwawt.macosx.CDataTransferer.translateTransferable(CDataTransferer.java:131)
at sun.awt.datatransfer.DataTransferer$6.run(DataTransferer.java:2304)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
I am using Eclipse Juno and Java SE 7 for Mac.
I don't understand it and can't find anything to solve it. I really fall into despair. Please help me.
Thank you in advance.
Update:
Code of HelloWorld.java
public class HelloWorld extends JFrame
{
public HelloWorld()
{
super("Hello, World!");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
}
finally
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
}
public static void main(String[] args)
{
HelloWorld frame = new HelloWorld();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}
You can workaround it by setting static field enableImageSupport to false. Like this : com.mxgraph.swing.util.mxGraphTransferable.enableImageSupport = false;
Source : http://jgraph.github.io/mxgraph/java/docs/com/mxgraph/swing/util/mxGraphTransferable.html#enableImageSupport
This appears to be something specific to OS X and some Java versions, looking at this bug report. This example works fine on the current Mac supplied JVM on OS X 10.8, namely:
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
Related
I have tried to run a simple game using Java and keep getting an error when I try to run this application.
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe ...
I think my problem is that my JDK (12.0.2) does not support these Slick2D as it is "OutDated". If downgrading my Java Version is a solution can someone please explain how I can find a version of Java that supports Slick2D?
I have already set up my libraries in my IDE and set my path. I tried to run the same application in the newest Intellij and eclipse environments. I currently have JDK 12.0.2 installed and a 2015 version of LWJGL plus Slick2D installed.
package classPackage;
import org.newdawn.slick.*;
public class Game extends BasicGame{
public Game(String gamename) {
super(gamename);
}
#Override
public void init(GameContainer gc) throws SlickException {
}
#Override
public void update(GameContainer gc, int i) throws SlickException {
}
#Override
public void render(GameContainer gc, Graphics g) throws SlickException {
g.drawString("Howdy!", 10, 10);
}
public static void main(String[] args) {
try {
AppGameContainer appgc;
appgc = new AppGameContainer(new Game("Simple Slick Game"));
appgc.setDisplayMode(640, 480, false);
appgc.start();
} catch (SlickException ex) {
}
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.getUnsafeInstance(MemoryUtilSun.java:74)
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.<init>(MemoryUtilSun.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at lwjgl/org.lwjgl.MemoryUtil.loadAccessor(MemoryUtil.java:375)
at lwjgl/org.lwjgl.MemoryUtil.<clinit>(MemoryUtil.java:63)
at lwjgl/org.lwjgl.opengl.WindowsDisplay.setTitle(WindowsDisplay.java:522)
at lwjgl/org.lwjgl.opengl.Display.setTitle(Display.java:541)
at lwjgl/org.lwjgl.opengl.Display.createWindow(Display.java:312)
at lwjgl/org.lwjgl.opengl.Display.create(Display.java:848)
at lwjgl/org.lwjgl.opengl.Display.create(Display.java:757)
at slick/org.newdawn.slick.AppGameContainer.tryCreateDisplay(AppGameContainer.java:302)
at slick/org.newdawn.slick.AppGameContainer.access$000(AppGameContainer.java:34)
at slick/org.newdawn.slick.AppGameContainer$2.run(AppGameContainer.java:353)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at slick/org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:348)
at slick/org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at testGame/classPackage.Game.main(Game.java:31)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 23 more
I was able to get this issue resolved by downgrading my jdk to 8. Thank you all I hope this will help someone in the future.
I added a SWT window to my project as
public class swtUI {
protected Shell shell;
protected Display display;
public static void launch() {
try {
swtUI window = new swtUI();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
// create all controls
blablabal
}
}
and call it in main() as
public static void main(String[] args) {
swtUI.launch();
System.out.println("\nComplete");
}
No problem running on Linux.
But when I replace the linux swt.jar with maxos swt.jar and run on mac, I got exception:
***WARNING: Display must be created on main thread due to Cocoa restrictions.
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.error(Unknown Source)
at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
at edu.rockefeller.casanovaLab.csvCheck.CsvSuiteGUI.open(CsvSuiteGUI.java:129)
at edu.rockefeller.casanovaLab.csvCheck.CsvSuiteGUI.launch(CsvSuiteGUI.java:119)
at edu.rockefeller.casanovaLab.csvCheck.Program.main(Program.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
I am pretty new to SWT. How should I change my code to make it work on mac?
Thanks
Seems this is mentioned in this FAQ. From the same link:
To work around this problem you'll have to pass the -XstartOnFirstThread option to the java executable as follows:
java -XstartOnFirstThread -cp swt.jar:. ControlExample
I get error message below when I run the HelloWorld.java example, out of JGraphX package.
Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/mxgraph/swing/mxGraphComponent, offset=6
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:275)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:540)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
at java.net.URLClassLoader.access$300(URLClassLoader.java:79)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1038)
at java.security.AccessController.doPrivileged(AccessController.java:284)
at java.net.URLClassLoader.findClass(URLClassLoader.java:429)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
source code HelloWorld.java
package com.test.jgraphxdemo;
import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
public class HelloWorld extends JFrame
{
/**
*
*/
private static final long serialVersionUID = -2707712944901661771L;
public HelloWorld()
{
super("Hello, World!");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30);
Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
}
finally
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
}
public static void main(String[] args)
{
HelloWorld frame = new HelloWorld();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}
I am using Eclipse and Java SE 6.
And it works well when i turn my jdk to 7. But According to jGraphx project doc here, it should support compiler version 1.5 and above.
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
<maven.compiler.compilerVersion>1.5</maven.compiler.compilerVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
I am totally in a mess now. Please help.Thanks a lot.
The library is built with JDK 7 by default. If you want support for an earlier Java version, just rebuild the library with the appropriate compliance flags.
I have tried
ClassWriter t = new ClassWriter(0);
t.visitSource("testing.java", null);
t.visitEnd();
byte d[] = t.toByteArray();
FileOutputStream p = null;
try
{
p = new FileOutputStream("testing.class");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
try
{
p.write(d);
}
catch (IOException e)
{
e.printStackTrace();
}
And the text within the testing.java is:
public class testing
{
public static void main(String args[])
{
System.out.println("Works!");
}
}
However, When I try to run the class file, it gives me this error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: testing : Unsupported major.minor version 0.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)
How would I fix it so that the class file would output "Works!" to the console?
Edit:
I don't want it to have to access the jdk files! (<- Ex. javax.tools) That's why I was trying to get ASM to work.
Seems that you are trying to compile Java source file into a class file. That can be done with the Java compiler - the javac command line program or the tools in the javax.tools package.
ASM is for a different purpose. ASM can be used to create class files on-the-fly, without any source code. Read ASM's documentation to learn about Java bytecode and how to produce and read it with ASM.
Here is how a file is compiled using javax.tools package. Or then you could invoke the command line tools using Process. Check the documentation for additional arguments - what classpath to use, where to write the files etc.
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class TestingCompile {
public static void main(String[] args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
int result = javac.run(null, null, null, "C:\\path\\to\\Testing.java");
if (result != 0) {
throw new RuntimeException("compile failed: exit " + result);
}
}
}
Here is how to create the same class file using ASM, without using the source file. I'm quite sure this is not what you want to be doing - otherwise you wouldn't have had to ask the question. ;)
This is just the output of ASMifierClassVisitor, so the bytes would still need to be written to a file or loaded dynamically into the class loader. I used the -debug argument so that ASMifier would show also the source file name and line numbers (the visitSource, visitLineNumber and visitLocalVariable calls are optional, so you could omit them and the related labels if the debug information is not needed).
import org.objectweb.asm.*;
public class TestingDump implements Opcodes {
public static byte[] dump() throws Exception {
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "Testing", null, "java/lang/Object", null);
cw.visitSource("Testing.java", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(1, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "LTesting;", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(3, l0);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("Works!");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLineNumber(4, l1);
mv.visitInsn(RETURN);
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitLocalVariable("args", "[Ljava/lang/String;", null, l0, l2, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
}
I believe the problem is that the library expects a minimum set of certain methods will be called and I believe you don't have enough methods to have it generate a full class.
I suggest you use ASMifier to generate some templates.
You have corrupted the file in some way. There was no version 0.0
You can invoke the Java compiler from your source code to compile any Java source code to the class files. The compiler is written in Java itself and part of the standard jdk release. Try to look for a class called javac.
I've just tried running the sample java files that I got with the epson tm-t20 printer that I bought. These classes should run but they keep giving me errors. I've been looking at this for over 8 hours now I'm really getting frustrated. This is the exception it's throwing at me:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/DOMParser
at jpos.config.simple.xml.AbstractXercesRegPopulator.<init>(Unknown Source)
at jpos.config.simple.xml.XercesRegPopulator.<init>(Unknown Source)
at jpos.config.simple.xml.SimpleXmlRegPopulator.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at jpos.loader.simple.SimpleServiceManager.initRegPopulator(Unknown Source)
at jpos.loader.simple.SimpleServiceManager.initEntryRegistry(Unknown Source)
at jpos.loader.simple.SimpleServiceManager.init(Unknown Source)
at jpos.loader.simple.SimpleServiceManager.<init>(Unknown Source)
at jpos.loader.JposServiceLoader.<clinit>(Unknown Source)
at jpos.BaseJposControl.open(Unknown Source)
at postest.Step1Frame.processWindowEvent(Step1Frame.java:83)
at java.awt.Window.processEvent(Window.java:2003)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Here's the sample code I've been looking at:
POSPrinterControl19 ptr = (POSPrinterControl19)new POSPrinter();
JPanel contentPane;
JPanel jPanel_reciept = new JPanel();
TitledBorder titledBorder1;
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
JButton jButton_Print = new JButton();
/**Construct "Frame"*/
public Step1Frame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Form the component*/
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Step1Frame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(134, 134, 134)),"Receipt");
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(300, 180));
this.setTitle("Step 1 Print \"Hello JavaPOS\"");
jPanel_reciept.setLayout(gridBagLayout2);
jPanel_reciept.setBorder(titledBorder1);
jButton_Print.setText("Print");
jButton_Print.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton_Print_actionPerformed(e);
}
});
contentPane.add(jPanel_reciept, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 20, 20));
jPanel_reciept.add(jButton_Print, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 10, 5, 10), 130, 0));
}
/**
* Outline The processing code required in order to enable
* or to disable use of service is written here.
* #exception JposException This exception is fired toward the failure of
* the method which JavaPOS defines.
*/
/**When the window was closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
this.closing();
}
/**When the window open*/
else if (e.getID() == WindowEvent.WINDOW_OPENED) {
// JavaPOS's code for Step1
try {
//Open the device.
//Use the name of the device that connected with your computer.
//ptr.clearPrintArea();
ptr.open("POSPrinter");
//Get the exclusive control right for the opened device.
//Then the device is disable from other application.
ptr.claim(1000);
//Enable the device.
ptr.setDeviceEnabled(true);
}
catch(JposException ex) {
}
}
// JavaPOS's code for Step1--END
}
//***********************Button*************************************************
/**
* Outline The code for using the most standard method "PrintNormal"
* to print is described.
*/
void jButton_Print_actionPerformed(ActionEvent e) {
// JavaPOS's code for Step1
try{
//printNormal(int station, String data)
//A string is sent by using the method "printNormal", and it is printed.
// "\n" is the standard code for starting a new line.
// When the end of the line have no "\n",printing by
// using the method "printNormal" doesn't start, may be.
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT,"Hello JavaPOS\n");
}
catch(JposException ex){
}
// JavaPOS's code for Step1--END
}
//***********************Method*************************************************
/**
* Outline The code to finish a service.
*/
void closing(){
// JavaPOS's code for Step1
try{
//Cancel the device.
ptr.setDeviceEnabled(false);
//Release the device exclusive control right.
ptr.release();
//Finish using the device.
ptr.close();
}
catch(JposException ex){
}
// JavaPOS's code for Step1--END
System.exit(0);
}
You have to put some additionally dependency library to the project classpath, one of them seems to be the apache xerces XML parser, so basically you have to add that jar library to the classpath .
you can find the apache xerces XML parser here .
For me class org/apache/xerces/parsers/DOMParser is missing. You can download it from maven repository xercesImpl.jar