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.
Related
I am developing a demo application with using GwtAI (Gwt Applet Integration). I have included all the GwtAI-client.jar,GwtAI-core.jar.I am referring to the http://code.google.com/p/gwtai/wiki/GettingStarted Following is the code.
FileUploadingApplet.class
#ImplementingClass(com.nextenders.appletImpl.FileUploadingAppletImpl.class)
#Height("60")
#Width("350")
#Archive("GwtAI-Client.jar,FileUploadingAppletImpl.jar")
#Codebase("applet")
public interface FileUploadingApplet extends Applet{
public void increment();
public void decrement();
public Object getCurrentValue();
}
FileUploadingAppletImpl.class
public class FileUploadingAppletImpl extends JApplet implements FileUploadingApplet {
JTextField m_fileNameTF = new JTextField(15);
String controlTransactionId = "";
JFileChooser m_fileChooser = new JFileChooser();
JPanel content = new JPanel();
FileWriter fstream = null;
long fileLength = 0l;
#Override
public void init() {
JPanel panelMain = new JPanel();
m_fileNameTF = new JTextField(20);
m_fileNameTF.setHorizontalAlignment(JTextField.CENTER);
m_fileNameTF.setText("0");
m_fileNameTF.setEditable(false);
panelMain.add(new JLabel("Current count : "));
panelMain.add(m_fileNameTF);
panelMain.setBorder(BorderFactory.createTitledBorder("CounterApplet"));
panelMain.setBackground(Color.WHITE);
getContentPane().add(panelMain);
}
public void increment() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount++;
m_fileNameTF.setText(currentCount + "");
}
public void decrement() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount--;
m_fileNameTF.setText(currentCount + "");
}
public Object getCurrentValue() {
return m_fileNameTF.getText();
}
}
NTFileUpload.java
private void createPanel(){
PopupPanel panel = new PopupPanel();
panel.setPopupPosition(500, 500);
panel.setHeight("600px");
panel.setHeight("900px");
final FileUploadingApplet fileUploadApplet = (FileUploadingApplet) GWT.create(FileUploadingApplet.class);
VerticalPanel panelMain = new VerticalPanel();
Button buttonInc = new Button("Increment");
buttonInc.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
fileUploadApplet.increment();
}
});
Widget widgetApplet = AppletJSUtil.createAppletWidget(fileUploadApplet);
panelMain.add(widgetApplet);
panelMain.add(buttonInc);
panel.add(panelMain);
panel.show();
}
I have followed the package structure as per the link. But I am getting following Exception.
java.lang.IncompatibleClassChangeError: Found interface com.google.gwt.core.ext.typeinfo.JClassType, but class was expected
at com.google.gwt.gwtai.applet.generator.AppletProxyGenerator.generate(AppletProxyGenerator.java:71)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:257)
at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:96)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:254)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:173)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:288)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$400(AbstractCompiler.java:139)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:588)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:97)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:52)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:569)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
at com.google.gwt.dev.Compiler.run(Compiler.java:232)
at com.google.gwt.dev.Compiler.run(Compiler.java:198)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
at com.google.gwt.dev.Compiler.main(Compiler.java:177)
Thanks in advance.
you need to build the dependencies that you're using (jar/war) with the same GWT SDK version that you are using for compilation of your project i.e. if 2.4 then use 2.4 to jar the dependencies and then compile your project. This error is due to the mismatch in the SDK versions being used.
There have been breaking changes in the GWT code generator feature, between version 1.7 and 2.0. So make sure you have the current version of GwtAI, if you work with a GWT version 2.0 or higher. If you work with a GWT version before 2.0 go to the GwtAI download page, select All downloads and click Search, you should see GwtAI 0.2 files. Those
should work with older GWT versions.
I am getting a NullPointerException when trying to open excel from SWT. Sadly I can't post the full stacktrace and some of the code because it has references to the company that I work for. Hopefully someone has run into this issue before and might recognize it.
Here is the part of the stacktrace that I can post
java.lang.NullPointerException
at org.eclipse.swt.ole.win32.OleControlSite.disconnectEventSinks(OleControlSite.java:468)
at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:774)
at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:909)
at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:895)
at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:129)
Here is the code. It's on the last line that the exception gets thrown, when a new OleControlSite is instantiated.
OleFrame frame1 = new OleFrame(shell, SWT.NONE);
if (clientSite != null && !clientSite.isDisposed()){
clientSite.dispose();
clientSite = null;
}
OleAutomation doc;
try{
clientSite = new OleControlSite(frame1, SWT.NONE, file);
This code works in windows XP, but not in windows 7 it throws the NullPointerException.
As per cubic suggestion I created a self contained example here is the code.
package com.test;
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleEvent;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.OleListener;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
public class OpenExcelExampleWindow extends Shell {
public final static int WorkbookBeforeClose = 0x00000622;
/**
* Launch the application.
* #param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
OpenExcelExampleWindow shell = new OpenExcelExampleWindow(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
* #param display
*/
public OpenExcelExampleWindow(Display display) {
super(display, SWT.SHELL_TRIM);
Button btnOpenExcel = new Button(this, SWT.NONE);
btnOpenExcel.setBounds(10, 10, 68, 23);
btnOpenExcel.setText("open excel");
btnOpenExcel.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
onOpenExcelClicked();
}
});
createContents();
}
protected void onOpenExcelClicked() {
openExcel("testfile.xls",this);
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(450, 300);
}
#Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
protected void openExcel(String fileName, Shell shell){
OleControlSite clientSite = null;
final File file = new File(fileName);
if (file.exists()) {
OleFrame frame1 = new OleFrame(shell, SWT.NONE);
if (clientSite != null && !clientSite.isDisposed()){
clientSite.dispose();
clientSite = null;
}
clientSite = new OleControlSite(frame1, SWT.NONE, file);
OleAutomation doc = new OleAutomation(clientSite);
int [] dispInfo = doc.getIDsOfNames(new String[] {"Application"});
Variant variant = doc.getProperty(dispInfo[0]);
OleAutomation app = variant.getAutomation();
variant.dispose();
doc.dispose();
doc = null;
int result = clientSite.doVerb(OLE.OLEIVERB_OPEN);
if (result != OLE.S_OK){
OLE.error(OLE.ERROR_CANNOT_OPEN_FILE, result);
}
//When user close workbook, dispose the clientSite.
clientSite.addEventListener(app, "{00024413-0000-0000-C000-000000000046}",
WorkbookBeforeClose,new OleListener() {
public void handleEvent(OleEvent event) {
OleControlSite oldControlSite = (OleControlSite)event.widget;
if ( !oldControlSite.isDisposed()){
//System.out.println("event in WorkbookBeforeClose");
oldControlSite.dispose();
}
}
});
}
}
}
And here is the exception
java.lang.NullPointerException
at org.eclipse.swt.ole.win32.OleControlSite.disconnectEventSinks(OleControlSite.java:468)
at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:774)
at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:909)
at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:895)
at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:129)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
at org.eclipse.swt.widgets.Widget.release(Widget.java:808)
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:446)
at org.eclipse.swt.ole.win32.OleClientSite.<init>(OleClientSite.java:194)
at org.eclipse.swt.ole.win32.OleControlSite.<init>(OleControlSite.java:96)
at com.test.OpenExcelExampleWindow.openExcel(OpenExcelExampleWindow.java:93)
at com.test.OpenExcelExampleWindow.onOpenExcelClicked(OpenExcelExampleWindow.java:65)
at com.test.OpenExcelExampleWindow$1.widgetSelected(OpenExcelExampleWindow.java:57)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at com.test.OpenExcelExampleWindow.main(OpenExcelExampleWindow.java:33)
Update:
I created an entirely new project with maven and just added one dependency for eclipse sdk 4.2 here is my pom file you can see there is only one dependency. The code in the project is the same as the class above.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>excelopen</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>excelopen</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>swt-win32-x86_64</artifactId>
<version>4.2_3.100.0.v4233d</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I noticed that the source code for the OleControlSite class is the same from 3.8 sdk to the 4.2 sdk, which makes it unlikely that it's the SDK version that's causing the issue for me.
Update:
I download the SWT Source code and the exception get's thrown at line 392 of OleClientSite at this line.
if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result)
And the hidden exception is
org.eclipse.swt.SWTException: Failed to create Ole Client. result = -2147221164
at org.eclipse.swt.ole.win32.OLE.error(OLE.java:302)
at org.eclipse.swt.ole.win32.OleClientSite.OleCreate(OleClientSite.java:392)
at org.eclipse.swt.ole.win32.OleClientSite.<init>(OleClientSite.java:192)
at org.eclipse.swt.ole.win32.OleControlSite.<init>(OleControlSite.java:96)
at com.test.OpenExcelExampleWindow.openExcel(OpenExcelExampleWindow.java:93)
at com.test.OpenExcelExampleWindow.onOpenExcelClicked(OpenExcelExampleWindow.java:65)
at com.test.OpenExcelExampleWindow$1.widgetSelected(OpenExcelExampleWindow.java:57)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at com.test.OpenExcelExampleWindow.main(OpenExcelExampleWindow.java:33)
Update 09/05 9:35am
Thanks to favonius's information I was able to find out some more information. I found this discussion about 32bit com's on a 64bit windows OS. This is where the 32bit com on 64bit is discussed.
http://www.eclipse.org/forums/index.php/mv/msg/264018/763345/
This might be my issue as we are running Office 2007 which only comes in 32bit and it's running on a 64bit OS. I would like to check the registry but I don't know what key's I should look up. Does anyone know what the registry key is?
Update 09/05 9:45am
Here are the results of the TestCode class that favonius provided.
Run 1 with line 57 commented
{00020820-0000-0000-C000-000000000046}
Excel.Sheet.8
org.eclipse.swt.SWTException: Failed to create Ole Client. result = -2147221164
at org.eclipse.swt.ole.win32.OLE.error(OLE.java:302)
at com.test.TestCode.check(TestCode.java:62)
at com.test.TestCode.main(TestCode.java:23)
Run 2 line 57 uncommented
{00020820-0000-0000-C000-000000000046}
Excel.Sheet.8
Update 09/05 1:51pm
Our app outputs an xls file for excel to open. I just tried reading in an xlsx file and it works. This is a reasonable change to fix the problem with this specific app. Is it not supposed to open xls files?
Dissecting the Problem
As per your last update, where you mentioned the origin of the exception, the problem lies in the following lines.
int /*long*/[] ppv = new int /*long*/[1];
result = COM.CoCreateInstance(appClsid, 0, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, COM.IIDIUnknown, ppv);
if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);
Now the second line in the above code is trying create a single uninitialized object of the class associated with a specified CLSID. Now in your case you are directly providing the XLSX file path, and therefore it uses the GetClassFile() which returns the CLSID associated with the specified file name. Now if it would have failed then you should have gotten the exception at line 186 of OleClientSite. Also, you are able to get a proper program id from the file class id otherwise an exception at line 189 would have resulted.
Checking the Error Code
In your stacktrace you got an error code -2147221164. Now to check what it really means. Start up your Visual Studio and select from menu Tools -> Error Lookup. Put the error code there and click lookup. And it gives...
Now the question is if the class is not registered then you should have got this problem while getting the program id from the class id at line 189. And this makes thing weird. Therefore, before proceeding ahead follow the Second Check.
As per MSDN entry of CoCreateInstance, the above error message could also mean thatthe type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.
Second Check
As a second check and to nail the real problem, just try this SWT Snippet and update the result in your question.
Third Check
I have written this simple test class. Try to run it and post the console output. Also, uncomment the line 57 and run again and post its output too.
Note - You have to change the File constructor parameter.
import java.io.File;
import org.eclipse.swt.internal.ole.win32.COM;
import org.eclipse.swt.internal.ole.win32.GUID;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestCode
{
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Excel Example");
shell.setLayout(new FillLayout());
try{
check(new File("output.xlsx"));
}catch(Exception e){
e.printStackTrace();
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
static void check(File file)
{
GUID fileClsid = new GUID();
char[] fileName = (file.getAbsolutePath()+"\0").toCharArray();
int result = COM.GetClassFile(fileName, fileClsid);
if (result != COM.S_OK)
OLE.error(OLE.ERROR_INVALID_CLASSID, result);
System.out.println(fileClsid);
String progID = getProgID(fileClsid);
if (progID == null)
OLE.error(OLE.ERROR_INVALID_CLASSID, result);
System.out.println(progID);
int [] ppv = new int[1];
int server_type = COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER;
//server_type |= COM.CLSCTX_LOCAL_SERVER;
result = COM.CoCreateInstance(fileClsid, 0, server_type, COM.IIDIUnknown, ppv);
if (result != COM.S_OK)
OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);
}
static String getProgID(GUID clsid)
{
if (clsid != null)
{
int [] lplpszProgID = new int [1];
if (COM.ProgIDFromCLSID(clsid, lplpszProgID) == COM.S_OK)
{
int hMem = lplpszProgID[0];
int length = OS.GlobalSize(hMem);
int ptr = OS.GlobalLock(hMem);
char[] buffer = new char[length];
COM.MoveMemory(buffer, ptr, length);
OS.GlobalUnlock(hMem);
OS.GlobalFree(hMem);
String result = new String(buffer);
int index = result.indexOf("\0");
return result.substring(0, index);
}
}
return null;
}
}
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)
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