Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/03/2015, 23:21
REHome
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 17 años
Puntos: 8
Netbeans 8 y encontrar fallos.

Hola:

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
  1. import gnu.io.CommPortIdentifier;
  2. import gnu.io.SerialPort;
  3. import java.io.OutputStream;
  4. import java.util.Enumeration;
  5. import javax.swing.JOptionPane;
  6.  
  7. /*
  8.  * To change this license header, choose License Headers in Project Properties.
  9.  * To change this template file, choose Tools | Templates
  10.  * and open the template in the editor.
  11.  */
  12.  
  13. /**
  14.  *
  15.  * @author Meta
  16.  */
  17. public class JAVADUINO_JFrame extends javax.swing.JFrame {
  18.  
  19.     /**
  20.      * Creates new form JAVADUINO_JFrame
  21.      */
  22.    
  23.     private static final String L8ON = "Led_8_ON";
  24.     private static final String L8OFF = "Led_8_OFF";
  25.    
  26.     // Variables de conexión.
  27.     private final OutputStream output = null;
  28.     SerialPort serialPort;
  29.     private final String PUERTO = "COM4";
  30.    
  31.     private static final int TIMEOUT = 2000;
  32.    
  33.     private static final int DATA_RATE = 115200;
  34.    
  35.     public JAVADUINO_JFrame() {
  36.         initComponents();
  37.         inicializarConexion();
  38.     }
  39.  
  40.     public final void inicializarConexion(){
  41.         CommPortIdentifier puertoID = null;
  42.         Enumeration puertoEnum = CommPortIdentifier.getPortIdentifiers();
  43.        
  44.         while(puertoEnum.hasMoreElements()){
  45.             CommPortIdentifier actualPuertoID = (CommPortIdentifier) puertoEnum.nextElement();
  46.             if (PUERTO.equals(actualPuertoID.getName())){
  47.                 puertoID = actualPuertoID;
  48.                 break;
  49.             }
  50.         }
  51.     }
  52.    
  53.     if (puertoID == null){
  54.     mostrarError("No se puede conectar al puerto.");
  55.     System.exit(ERROR);
  56. }
  57.    
  58.     try{
  59.         serialPort = (SerialPort) puertoID.open(this.getClass().getName(), TIMEOUT);
  60.         // Parámetros puerto serie.
  61.         serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_2, SerialPort.PARITY_NONE);
  62.         output = serialPort.getOutputStream();
  63. }
  64.     catch (Exception e){
  65.     mostrarError(e.getMessage());
  66.     System.exit(ERROR);
  67. }
  68.  
  69.     private void enviarDatos(String datos){
  70.         try{
  71.             output.write(datos.getBytes());
  72.         }
  73.         catch(Exception e){
  74.             mostrarError("ERROR");
  75.             System.exit(ERROR);
  76.         }
  77.     }
  78.    
  79.     public void mostrarError(String mensaje){
  80.         JOptionPane.showMessageDialog(this, mensaje, "ERROR", JOptionPane.ERROR_MESSAGE);
  81.        
  82.     }
  83.     /**
  84.      * This method is called from within the constructor to initialize the form.
  85.      * WARNING: Do NOT modify this code. The content of this method is always
  86.      * regenerated by the Form Editor.
  87.      */
  88.     @SuppressWarnings("unchecked")
  89.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  90.     private void initComponents() {
  91.  
  92.         jButton1 = new javax.swing.JButton();
  93.         jButton2 = new javax.swing.JButton();
  94.  
  95.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  96.  
  97.         jButton1.setText("ON");
  98.  
  99.         jButton2.setText("OFF");
  100.  
  101.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  102.         getContentPane().setLayout(layout);
  103.         layout.setHorizontalGroup(
  104.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  105.             .addGroup(layout.createSequentialGroup()
  106.                 .addGap(21, 21, 21)
  107.                 .addComponent(jButton1)
  108.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
  109.                 .addComponent(jButton2)
  110.                 .addGap(45, 45, 45))
  111.         );
  112.         layout.setVerticalGroup(
  113.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  115.                 .addContainerGap(250, Short.MAX_VALUE)
  116.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  117.                     .addComponent(jButton1)
  118.                     .addComponent(jButton2))
  119.                 .addGap(27, 27, 27))
  120.         );
  121.  
  122.         pack();
  123.     }// </editor-fold>                        
  124.  
  125.     /**
  126.      * @param args the command line arguments
  127.      */
  128.     public static void main(String args[]) {
  129.         /* Set the Nimbus look and feel */
  130.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  131.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  132.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  133.          */
  134.         try {
  135.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  136.                 if ("Nimbus".equals(info.getName())) {
  137.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  138.                     break;
  139.                 }
  140.             }
  141.         } catch (ClassNotFoundException ex) {
  142.             java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  143.         } catch (InstantiationException ex) {
  144.             java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  145.         } catch (IllegalAccessException ex) {
  146.             java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  147.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  148.             java.util.logging.Logger.getLogger(JAVADUINO_JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  149.         }
  150.         //</editor-fold>
  151.  
  152.         /* Create and display the form */
  153.         java.awt.EventQueue.invokeLater(new Runnable() {
  154.             public void run() {
  155.                 new JAVADUINO_JFrame().setVisible(true);
  156.             }
  157.         });
  158.     }
  159.  
  160.     // Variables declaration - do not modify                    
  161.     private javax.swing.JButton jButton1;
  162.     private javax.swing.JButton jButton2;
  163.     // End of variables declaration                  
  164.  
  165.     private void mostrarError(String no_se_puede_conectar_al_puerto) {
  166.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  167.     }
  168. }

Todavía no he programado los botones, hay que acabar con los fallos primero. Los mensajes que me dan son estos.
Cita:
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)
He segudio los tutoriales hasta el minuto 37':30" de este vídeo.
https://www.youtube.com/watch?v=4Hr_LZ62SdY

¿Alguna idea?

Saludos.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar