Tengo un código medio hecho en el cual no se el motivo de los fallos. Se trata de encender y apagar un Led con Netbeans 8 en mi caso y Arduino.
Código Java:
Ver original
import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import java.io.OutputStream; import java.util.Enumeration; import javax.swing.JOptionPane; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Meta */ /** * Creates new form JAVADUINO_JFrame */ // Variables de conexión. SerialPort serialPort; private static final int TIMEOUT = 2000; private static final int DATA_RATE = 115200; public JAVADUINO_JFrame() { initComponents(); inicializarConexion(); } public final void inicializarConexion(){ CommPortIdentifier puertoID = null; while(puertoEnum.hasMoreElements()){ CommPortIdentifier actualPuertoID = (CommPortIdentifier) puertoEnum.nextElement(); if (PUERTO.equals(actualPuertoID.getName())){ puertoID = actualPuertoID; break; } } } if (puertoID == null){ mostrarError("No se puede conectar al puerto."); } try{ serialPort = (SerialPort) puertoID.open(this.getClass().getName(), TIMEOUT); // Parámetros puerto serie. serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_2, SerialPort.PARITY_NONE); output = serialPort.getOutputStream(); } mostrarError(e.getMessage()); } try{ output.write(datos.getBytes()); } mostrarError("ERROR"); } } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton1.setText("ON"); jButton2.setText("OFF"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) .addComponent(jButton1) .addComponent(jButton2) .addGap(45, 45, 45)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addGap(27, 27, 27)) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { break; } } java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ public void run() { new JAVADUINO_JFrame().setVisible(true); } }); } // Variables declaration - do not modify // End of variables declaration throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }
Todavía no he programado los botones, hay que acabar con los fallos primero. Los mensajes que me dan son estos.
Cita:
He segudio los tutoriales hasta el minuto 37':30" de este vídeo.run:
java.lang.ClassFormatError: Duplicate field name&signature in class file JAVADUINO_JFrame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:455)
at java.net.URLClassLoader.access$100(URLClassLoader. java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 367)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:495)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
java.lang.ClassFormatError: Duplicate field name&signature in class file JAVADUINO_JFrame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:455)
at java.net.URLClassLoader.access$100(URLClassLoader. java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 367)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:495)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
https://www.youtube.com/watch?v=4Hr_LZ62SdY
¿Alguna idea?
Saludos.