如何解决错误“线程中的异常”AWT-EventQueue-0“java.lang.NullPointerException:”?

时间:2013-05-14 12:15:04

标签: java arm openjdk

我制作了MyApp for arm处理器(ARMv7,512 RAM,Debian Wheezy OS,Openjdk-7安装)。 当我在这个操作系统上运行MyApp时,它会出错。我的代码和错误如下。我根据错误搜索,但我无法解决该错误。 MyApp在安装了Windows 7和Ubuntu 12.04的Pc上运行良好。那么任何人都有想法或解决方案而不是向我建议吗?

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author JAY_2
 */
public class MyApp extends JPanel {

    /**
     * @param args the command line arguments
     */
    public static javax.swing.JTextField inpuText;
    private javax.swing.JLabel inputLbl;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel outPutLbl;
    public static javax.swing.JTextArea outPuttextArea;
    private javax.swing.JLabel tempLbl;
    public static javax.swing.JLabel tempShowLbl;
    public static javax.swing.JTextArea temptextArea;

    public MyApp() {
        // TODO code application logic here
        setComponents();
    }

    private void setComponents() {
        tempLbl = new javax.swing.JLabel("Temperature :");
        tempShowLbl = new javax.swing.JLabel("Label");
        inputLbl = new javax.swing.JLabel("InPut :");
        inpuText = new javax.swing.JTextField();
        outPutLbl = new javax.swing.JLabel("OutPut :");
        jScrollPane1 = new javax.swing.JScrollPane();
        outPuttextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        temptextArea = new javax.swing.JTextArea(55000, 10);

        this.setBackground(new java.awt.Color(204, 255, 255));

        tempLbl.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

        tempShowLbl.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N        

        inputLbl.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        inpuText.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        inpuText.setText(""); // NOI18N

        outPutLbl.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        outPuttextArea.setColumns(20);
        outPuttextArea.setRows(5);
        jScrollPane1.setViewportView(outPuttextArea);

        temptextArea.setColumns(20);
        temptextArea.setRows(10);
        jScrollPane2.setViewportView(temptextArea);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(this);
        this.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addComponent(inputLbl).addContainerGap(482, Short.MAX_VALUE)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(outPutLbl).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE).addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(jPanel1Layout.createSequentialGroup().addComponent(inpuText, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE).addComponent(tempLbl).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(tempShowLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))).addGap(36, 36, 36)))));
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(inputLbl).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(inpuText, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(tempLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(tempShowLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addGap(43, 43, 43).addComponent(outPutLbl).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)).addGroup(jPanel1Layout.createSequentialGroup().addGap(3, 3, 3).addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))).addContainerGap()));

    }

    public static void main(String[] args) {
        // TODO code application logic here
        JFrame jFrame = new JFrame();
        jFrame.add(new MyApp());
        jFrame.setSize(500, 400);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);
    }
}

错误:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: 
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.compareAndSetState(AbstractQueuedSynchronizer.java:566)
    at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:211)
    at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:290)
    at sun.awt.SunToolkit.flushPendingEvents(SunToolkit.java:551)
    at java.awt.EventQueue.postEvent(EventQueue.java:240)
    at sun.awt.PostEventQueue.flush(SunToolkit.java:2024)
    at sun.awt.SunToolkit.flushPendingEvents(SunToolkit.java:560)
    at java.awt.EventQueue.getNextEvent(EventQueue.java:523)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:180)
    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)
Exception in thread "AWT-XAWT" java.lang.NullPointerException: 
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.compareAndSetState(AbstractQueuedSynchronizer.java:566)
    at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:211)
    at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:290)
    at sun.awt.SunToolkit.awtLock(SunToolkit.java:237)
    at sun.awt.X11.XBaseWindow.ungrabInput(XBaseWindow.java:883)
    at sun.awt.X11.XToolkit.run(XToolkit.java:675)
    at sun.awt.X11.XToolkit.run(XToolkit.java:591)
    at java.lang.Thread.run(Thread.java:722)

2 个答案:

答案 0 :(得分:2)

删除OpenJdk-7版本并为ARM处理器和Hard Float Os Image安装Oracle Jdk。 这是链接。Oracle JDK for ARM processor

答案 1 :(得分:0)

通过在EventDispatchThread中执行代码重试此操作:

public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                 JFrame jFrame = new JFrame();
                    jFrame.add(new MyApp());
                    jFrame.setSize(500, 400);
                    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    jFrame.setVisible(true);

            }
        });
    }