i'm implementing a client/server app with java RMI, client and server are in different packages in the same project (and of course they run on the same machine) and interfaces are defined in a "common" package.When i try to get one of the two remote object i get the aforementioned excepition. I've read some SO answers where people sugget to add a static reference to remote object so they can be never collected, but this doesn't work!
here is the code of the client and server
NotificheServiceProxy
public class NotificheServiceProxy implements INotificheService
{
#Override
public ArrayList <NotificaDTO> generaNotifiche(String autostrada, Date data, Date oraInizio, Date oraFine)
{
try
{
RMIClient client = new RMIClient ("localhost" , 1099);
INotificheService service = (INotificheService) client.getService(INotificheService.class);
return service.generaNotifiche(autostrada, data, oraInizio, oraFine);
}
catch (RemoteException ex)
{
Logger.getLogger(TrattaServiceProxy.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
catch (NotBoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
RMIClient
public class RMIClient
{
private Registry reg;
public RMIClient (String url , int port) throws RemoteException
{
reg = LocateRegistry.getRegistry(url, port);
}
public Remote getService(Class service) throws NotBoundException, RemoteException
{
RMIMapping RMIMappingAnn = (RMIMapping) service.getAnnotation(RMIMapping.class);
return reg.lookup(RMIMappingAnn.name());
}
}
NotificheService (server side)
public class NotificheService implements INotificheService
{
private static NotificheService instance;
#Override
public ArrayList<NotificaDTO> generaNotifiche(String autostrada, Date data, Date oraInizio, Date oraFine) throws RemoteException
{
instance = this;
return new NotificheBusinessLogic().generaNotifiche(autostrada, data, oraInizio, oraFine);
}
}
scServerConfig (server main)
public class SCServerConfig
{
public static RMIServer server;
public static void main (String[] args)
{
server = new RMIServer(1099);
//avvia il server ed esporta oggetti remoti
server.start().export(TrattaService.class).export(NotificheService.class);
//Other stuff
RMIServer (starts server and provide method for remote objects exporting
public class RMIServer
{
private Registry reg;
private int regPort;
public RMIServer (int regPort)
{
this.regPort = regPort;
}
public RMIServer start()
{
try
{
reg = LocateRegistry.createRegistry(regPort);
System.out.println("SERVER OK");
}
catch (RemoteException ex)
{
Logger.getLogger(RMIServer.class.getName()).log(Level.SEVERE, null, ex);
}
return this;
}
public RMIServer export (Class object)
{
try
{
RMIMapping RMIMappingAnn = (RMIMapping) object.getInterfaces()[0].getAnnotation(RMIMapping.class);
Remote tmp = UnicastRemoteObject.exportObject((Remote)object.newInstance(), 0);
reg.rebind( RMIMappingAnn.name() , tmp );
System.out.println("oggetto remoto esportato " + object);
}
catch (InstantiationException ex)
{
System.err.println("InstantiationExeception!!\ncause:\n 1. il costruttore dell' oggetto remoto non deve avere argomenti");
}
catch (IllegalAccessException ex)
{
Logger.getLogger(RMIServer.class.getName()).log(Level.SEVERE, null, ex);
}
catch (RemoteException ex)
{
Logger.getLogger(RMIServer.class.getName()).log(Level.SEVERE, null, ex);
}
return this;
}
}
Each interface is annotated with #RMIMapping annotation that provides the object binding name. But i'm sure that the problem doesn'come from this
This is for me a real mistery, this is the stacktrace......many thanks for help!
ott 03, 2014 5:13:17 PM it.csbeng.speedcontrolsystem.addettoApp.proxy.NotificheServiceProxy generaNotifiche
SEVERE: null
java.rmi.NoSuchObjectException: no such object in table
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at $Proxy3.generaNotifiche(Unknown Source)
at it.csbeng.speedcontrolsystem.addettoApp.proxy.NotificheServiceProxy.generaNotifiche(NotificheServiceProxy.java:25)
at it.csbeng.speedcontrolsystem.addettoApp.coordinator.AddettoAppCoordinator.generaNotifiche(AddettoAppCoordinator.java:17)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction.generaNotificheEvent(AddettoInteraction.java:179)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction.access$000(AddettoInteraction.java:15)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction$1.mousePressed(AddettoInteraction.java:78)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
at java.awt.Component.processMouseEvent(Component.java:6502)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
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:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at it.csbeng.speedcontrolsystem.addettoApp.coordinator.AddettoAppCoordinator.generaNotifiche(AddettoAppCoordinator.java:20)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction.generaNotificheEvent(AddettoInteraction.java:179)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction.access$000(AddettoInteraction.java:15)
at it.csbeng.speedcontrolsystem.addettoApp.boundary.AddettoInteraction$1.mousePressed(AddettoInteraction.java:78)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
at java.awt.Component.processMouseEvent(Component.java:6502)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
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:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
EDIT: #EJP before that, i've done something like
public class RemoteObject implements IRemoteObject
{
private static RemoteObject instance;
public RemoteObject ()
{
instance = this;
}
public someType someMethod (...)
}
but it throwed the same exception. Furthermore, as you can see, in scServerConfig there is a
public static RMIServer server;
which encapsulates a Registry reference. if these thing i've done are correct, i think that adding static references may not be enough, even tough "suddendly" started to work for me. Am I wrong?
java.rmi.NoSuchObjectException but static reference added
It isn't added. You're trying to call the remote method that adds it. You're failing at that, so it hasn't hapoened yet.
You need to set the static instance in the constructor of your remote object. Doing it in the remote method may already be too late.
I suggest you also keep the Registry in a static variable server side. In fact strictly speaking that's the only reference you need to keep static.
Related
When I run this simple Java8 program
package test;
public class TraceInt {
public static void main(String args[]) throws InterruptedException{
TraceInt ti = new TraceInt();
while(true){
Integer.valueOf((int)System.currentTimeMillis());
ti.sleep(1000);
//System.getProperty("user.dir");
}
}
public void sleep(int millis){
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
And run this btrace script against it
#OnMethod(
clazz = "/.*/",
method = "/java.lang.*/",
location = #Location(value = Kind.ENTRY, where = Where.BEFORE)
)
public static void onEntry(Object obj) {
println(Strings.strcat("on entry: ", identityStr(obj)));
}
I get this error in the program
java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitMethodInsn(Unknown Source)
at com.sun.btrace.util.templates.TemplateExpanderVisitor.visitMethodInsn(TemplateExpanderVisitor.java:85)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitMethodInsn(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.a(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.b(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:66)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:62)
at com.sun.btrace.agent.Client.instrument(Client.java:392)
at com.sun.btrace.agent.Client.doTransform(Client.java:213)
at com.sun.btrace.agent.Client.transform(Client.java:165)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
at com.sun.btrace.agent.Main$4.run(Main.java:464)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Any help appreciated
After a while I realised I was using an old version of btrace against Java8. As soon as I moved to the latest version everything was fine.
Can someone help me here with my little Java/MySQL Database tool?
Part of the code is as follows, but when clicking on the createCustomerButton the DBMS tells me, that my syntax is somehow wrong.
protected static JTextField nachnameField = new JTextField();
protected static JTextField vornameField = new JTextField();
protected static JTextField postleitzahlField = new JTextField();
protected static JTextField strasseField = new JTextField();
protected static JTextField emailField = new JTextField();
protected static JTextField telefonField = new JTextField();
protected static JTextField zusatzinfoField = new JTextField();
static JButton createCustomerButton = new JButton("Kunde anlegen");
...
public static void passStatement(String statementString)
throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
PreparedStatement preparedStmt = conn.prepareStatement(statementString);
preparedStmt.executeUpdate();
}
...
public class Listener extends Main implements ActionListener, MouseListener {
public void actionPerformed(ActionEvent ae) {
#Override
public void mouseClicked(MouseEvent me) {
if (me.getSource() == createCustomerButton) {
nachnameField.getText();
vornameField.getText();
strasseField.getText();
postleitzahlField.getText();
telefonField.getText();
emailField.getText();
zusatzinfoField.getText();
String statement = "INSERT INTO kunde (nachname, vorname, strasse,
postleitzahl, telefon, email, zusatzinfo) VALUES("+nachnameField+","
+vornameField+","+strasseField+","+postleitzahlField+","+telefonField+","
+emailField+","+zusatzinfoField+")";
try {
passStatement(statement);
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
createLowerPanel();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Full error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the right
syntax to use near'
[,322,4,461x19,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,
alignment' at line 1
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:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
at Main.passStatement(Main.java:66)
at Listener.mouseClicked(Listener.java:46)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6508)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3311)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
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:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Any help is greatly appreciated!!
If it is a string value that you are inputting to a SQL database then you need to put single quotes before and after each element e.g..
tring statement = "INSERT INTO kunde (nachname, vorname, strasse,
postleitzahl, telefon, email, zusatzinfo) VALUES('" + nachname + "','" // use variable here
+ vorname + "')"; // ...... etc...
Hope this is clear.
You're calling getText() on your JTextFields and just ignoring the String returned. Instead your passing the actual JTextField's toString result and not its text into your SQL statement. Don't do that.
So instead, get the text Strings from your fields, and put them into String variables. Then use those variables to build your SQL statement. i.e.,
String foo = fooTextField.getText();
// now use foo, not fooTextField to create your SQL statements.
i.e.,
if (me.getSource() == createCustomerButton) {
String nachname = nachnameField.getText(); // get text put into variable
String vorname = vornameField.getText();
// .... etc
String statement = "INSERT INTO kunde (nachname, vorname, strasse,
postleitzahl, telefon, email, zusatzinfo) VALUES(" + nachname + "," // use variable here
+ vorname + "," ...... etc...
Also:
Learn and then use PreparedStatements as these are safer to use.
Don't add MouseListeners to JButtons as this will lead to bad button behavior (i.e., disabled buttons that still work, buttons that don't respond to space bar presses...)
Use ActionListeners instead.
Don't overuse static modifier as you're doing. Using them in this way suggests that your code needs to be improved greatly.
Don't post bad snippets as you're doing as that will only confuse us.
I'm using IntelliJ IDEA 13, and I'm creating a desktop application using Maven and OpenJPA, but do not know why I get a error message, this error occurs when running the Main file, I start the application, but pressing search button for searching a "Cliente" in the database, this error occurs:
1006 sacPU WARN [AWT-EventQueue-0] openjpa.Enhance - An exception was thrown while attempting to perform class file transformation on "cl/im/sac/Model/Cliente":
java.lang.NoClassDefFoundError: cl.im.sac.Model.Entidad
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
at java.lang.Class.getDeclaredFields(Class.java:1760)
at org.apache.openjpa.lib.util.J2DoPrivHelper$7.run(J2DoPrivHelper.java:295)
at org.apache.openjpa.lib.util.J2DoPrivHelper$7.run(J2DoPrivHelper.java:293)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.determineImplicitAccessType(PersistenceMetaDataDefaults.java:364)
at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.determineAccessType(PersistenceMetaDataDefaults.java:332)
at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.populate(PersistenceMetaDataDefaults.java:274)
at org.apache.openjpa.meta.MetaDataRepository.addMetaData(MetaDataRepository.java:914)
at org.apache.openjpa.meta.MetaDataRepository.addMetaData(MetaDataRepository.java:899)
at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.getMetaData(AnnotationPersistenceMetaDataParser.java:752)
at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parseClassAnnotations(AnnotationPersistenceMetaDataParser.java:545)
at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parse(AnnotationPersistenceMetaDataParser.java:415)
at org.apache.openjpa.persistence.PersistenceMetaDataFactory.load(PersistenceMetaDataFactory.java:260)
at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:580)
at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:400)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:384)
at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:286)
at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:257)
at org.apache.openjpa.enhance.PCClassFileTransformer.transform0(PCClassFileTransformer.java:146)
at org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:126)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.openjpa.meta.MetaDataRepository.classForName(MetaDataRepository.java:1552)
at org.apache.openjpa.meta.MetaDataRepository.loadPersistentTypesInternal(MetaDataRepository.java:1528)
at org.apache.openjpa.meta.MetaDataRepository.loadPersistentTypes(MetaDataRepository.java:1506)
at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:282)
at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:238)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
at cl.im.sac.Dao.Persistencia.<clinit>(Persistencia.java:16)
at cl.im.sac.Dao.ClienteDao.<clinit>(ClienteDao.java:17)
at cl.im.sac.UI.Interfaz$1.actionPerformed(Interfaz.java:76)
This is the interface class.
public class Interfaz extends JFrame{
private JButton btnConsulta;
...
public Interfaz(){
super("Sistema de Atención Al Cliente");
setContentPane(rootPanel);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(900,600);
setVisible(true);
/*** LISTENERS ***/
btnConsulta.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
String rn= run.getText();
if (ValidateRUT.validate(rn)) {
Cliente cliente = ClienteDao.findByRUN(rn);
if (cliente != null) {
productos.setModel(new ProductoTableModel(cliente));
} else {
JOptionPane.showMessageDialog(null, "El cliente no ha sido encontrado en el sistema");
}
} else {
JOptionPane.showMessageDialog(null, "RUN Inválido", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
the "Entidad" class is an abstract class that inherits the toString method.
public abstract class Entidad {
private static ObjectMapper mapper = new ObjectMapper();
#Override
public String toString(){
try {
return mapper.writeValueAsString(this);
} catch (IOException e) {
e.printStackTrace();
return "error al mapear la entidad";
}
}
}
and the "Cliente" class is part of the model database and extends "Entidad" class.
#Table(name = "cliente", catalog = "sac")
#Entity
public class Cliente extends Entidad implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(nullable = false, unique = true)
private Long id;
...
#OneToMany(cascade = CascadeType.ALL)
private List<Producto> productos;
/** METHODS **/
}
I'm trying to costumize a Synthetica theme in netbeans as this article shows :
http://www.jyloo.com/news/?pubId=1335947397000
So, I created the costum.xml file and I added it to my project folder as : /home/aimad/NetBeansProjects/GestionStock/costum.xml
and I create this code in my Form constructor :
public PersonelMainForm() {
try {
try {
UIManager.setLookAndFeel(new SyntheticaStandardLookAndFeel() {
#Override
protected void loadCustomXML() throws ParseException {
loadXMLConfig("custom.xml");
}
});
setName("MainFrame");
getRootPane().updateUI();
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(PersonelMainForm.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (ParseException ex) {
Logger.getLogger(PersonelMainForm.class.getName()).log(Level.SEVERE, null, ex);
}
initComponents();
}
but when I run the program I get this error message :
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: You must supply an InputStream,
StyleFactory and Class or URL at
javax.swing.plaf.synth.SynthParser.parse(SynthParser.java:227) at
javax.swing.plaf.synth.SynthLookAndFeel.load(SynthLookAndFeel.java:573)
at
de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.loadXMLConfig(SyntheticaLookAndFeel.java:428)
at
Personel.PersonelMainForm$1.loadCustomXML(PersonelMainForm.java:34)
at
de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.(SyntheticaLookAndFeel.java:364)
at
de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel.(SyntheticaStandardLookAndFeel.java:30)
at Personel.PersonelMainForm$1.(PersonelMainForm.java:30) at
Personel.PersonelMainForm.(PersonelMainForm.java:30) at
Personel.PersonelMainForm$3.run(PersonelMainForm.java:159) at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727) at
java.awt.EventQueue.access$200(EventQueue.java:103) at
java.awt.EventQueue$3.run(EventQueue.java:688) at
java.awt.EventQueue$3.run(EventQueue.java:686) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697) at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
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