Home > Back-end >  The Exception in the thread "is the AWT - EventQueue - 0" Java. Lang. NullPointerException
The Exception in the thread "is the AWT - EventQueue - 0" Java. Lang. NullPointerException

Time:12-24

Is there a big help to solve by javaSwing serial port communication tool will get to the error between the virtual serial port communication no problem to hardware serial port to send data to receive less than the value returned, can also lead to software card dead code below

Package com. Yang. Serialport. UI;

import java.awt.Color;
Import the Java. The awt. GraphicsEnvironment;
Import the Java. The awt. Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

The import javax.mail. Swing. BorderFactory;
The import javax.mail. Swing. ButtonGroup;
The import javax.mail. Swing. JButton;
The import javax.mail. Swing. JComboBox;
The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JLabel;
The import javax.mail. Swing. JPanel;
The import javax.mail. Swing. JRadioButton;
The import javax.mail. Swing. The JScrollPane;
import javax.swing.JTextArea;
The import javax.mail. Swing. Event. PopupMenuEvent;
The import javax.mail. Swing. Event. PopupMenuListener;

The import com. Yang. Serialport. Manager. SerialPortManager;
The import com. Yang. Serialport. Utils. ByteUtils;
The import com. Yang. Serialport. Utils. ShowUtils;

Import the gnu. IO. PortInUseException;
Import the gnu. IO. SerialPort;

/* *
* main interface
*
* @ author yangle
*/
@ SuppressWarnings (" all ")
Public class MainFrame extends JFrame {

//program interface width
Public final int WIDTH=930;
//program interface height
Public final int HEIGHT=570;

//data display area
Private JTextArea mDataView=new JTextArea ();
Private JScrollPane mScrollDataView=new JScrollPane (mDataView);

//serial port Settings panel
Private JPanel mSerialPortPanel=new JPanel ();
Private JLabel mSerialPortLabel=new JLabel (" serial ");
Private JLabel mBaudrateLabel=new JLabel (" baud rate ");
Private JComboBox mCommChoice=new JComboBox ();
Private JComboBox mBaudrateChoice=new JComboBox ();
Private ButtonGroup mDataChoice=new ButtonGroup ();
Private JRadioButton mDataASCIIChoice=new JRadioButton (" ASCII ", true);
Private JRadioButton mDataHexChoice=new JRadioButton (" Hex ");

//operation panel
Private JPanel mOperatePanel=new JPanel ();
Private JTextArea mDataInput=new JTextArea ();
Private JButton mSerialPortOperate=new JButton (" open the serial port ");
Private JButton mSendData=https://bbs.csdn.net/topics/new JButton (" send data ");

//shortcut panel
Private JPanel mQuick=new JPanel ();
Private JButton m1=new JButton (" shortcuts 1 ");
Private JButton m2=new JButton (" shortcuts 2 ");

//serial port list
Private List MCommList=null;
//a serial port object
Private SerialPort mSerialport;

Public MainFrame () {
InitView ();
InitComponents ();
ActionListener ();
initData();
}

/* *
* initialize window
*/
Private void initView () {
//close the program
SetDefaultCloseOperation (javax.mail. Swing. WindowConstants. EXIT_ON_CLOSE);
//prohibited maximize window
SetResizable (false);

//setup window centered
Point p=GraphicsEnvironment. GetLocalGraphicsEnvironment (.) getCenterPoint ();
SetBounds (p.x - WIDTH/2, p.y - HEIGHT/2, WIDTH, HEIGHT);
Enclosing setLayout (null);

SetTitle (" a serial port tools ");
}

/* *
Initial control *
*/
Private void initComponents () {
//according to
MDataView. SetFocusable (false);
MScrollDataView. SetBounds (10, 10, 905, 300);
Add (mScrollDataView);

//serial port Settings
MSerialPortPanel. SetBorder (BorderFactory. CreateTitledBorder (" a serial port Settings "));
MSerialPortPanel. SetBounds (10, 320, 200, 190);
MSerialPortPanel. SetLayout (null);
Add (mSerialPortPanel);

MSerialPortLabel. SetForeground (Color. Gray);
MSerialPortLabel. SetBounds (10, 25, 40, 20).
MSerialPortPanel. Add (mSerialPortLabel);

MCommChoice. SetFocusable (false);
MCommChoice. SetBounds (60, 25, 100, 20).
MSerialPortPanel. Add (mCommChoice);

MBaudrateLabel. SetForeground (Color. Gray);
MBaudrateLabel. SetBounds (10, 60, 40, 20).
MSerialPortPanel. Add (mBaudrateLabel);

MBaudrateChoice. SetFocusable (false);
MBaudrateChoice. SetBounds (60, 60, 100, 20).
MSerialPortPanel. Add (mBaudrateChoice);

MDataASCIIChoice. SetBounds (20, 95, 55, 20).
MDataHexChoice. SetBounds (95, 95, 55, 20).
MDataChoice. Add (mDataASCIIChoice);
MDataChoice. Add (mDataHexChoice);
MSerialPortPanel. Add (mDataASCIIChoice);
MSerialPortPanel. Add (mDataHexChoice);

MSerialPortOperate. SetFocusable (false);
MSerialPortOperate. SetBounds (45, 128, 105, 35).
MSerialPortPanel. Add (mSerialPortOperate);

//
MOperatePanel. SetBorder (BorderFactory. CreateTitledBorder (" send data "));
MOperatePanel. SetBounds (217, 320, 330, 190);
MOperatePanel. SetLayout (null);
Add (mOperatePanel);

MDataInput. SetBounds (20, 20, 290, 90);
MDataInput. SetLineWrap (true);
MDataInput. SetWrapStyleWord (true);
MOperatePanel. Add (mDataInput);

/* mSerialPortOperate. SetFocusable (false);
MSerialPortOperate. SetBounds (45, 95, 90, 20).
MOperatePanel. Add (mSerialPortOperate); */

MSendData. SetFocusable (false);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related