20170204Exception in thread "main" java.lang.NullPointerException
2017-02-04 20:27
573 查看
Exception in thread "main" java.lang.NullPointerException
at com.txw.Ftest.getControlPanel(Ftest.java:28)
at com.txw.Ftest.getJContentPane(Ftest.java:93)
at com.txw.Ftest.initialize(Ftest.java:85)
at com.txw.Ftest.<init>(Ftest.java:81)
at com.txw.Ftest.main(Ftest.java:99)
at com.txw.Ftest.getControlPanel(Ftest.java:28)
at com.txw.Ftest.getJContentPane(Ftest.java:93)
at com.txw.Ftest.initialize(Ftest.java:85)
at com.txw.Ftest.<init>(Ftest.java:81)
at com.txw.Ftest.main(Ftest.java:99)
public class Ftest extends JFrame { private JScrollPane scrollPane; private static final long serialVersionUID=1L; private JPanel jContentPane=null; private JTextArea jTextArea=null; private JPanel controlPanel=null; private JButton openButton=null; private JButton closeButton=null; private JTextArea getJTextArea(){ if(jTextArea==null){ jTextArea=new JTextArea(); } return jTextArea; } private JPanel getControlPanel(){ if(controlPanel==null){ FlowLayout flowLayout=new FlowLayout(); flowLayout.setVgap(1); controlPanel=new JPanel(); //缺少此行就会报错 controlPanel.setLayout(flowLayout); controlPanel.add(getOpenButton(), null); controlPanel.add(getCloseButton(),null); } return controlPanel; } private JButton getOpenButton(){ if(openButton==null){ openButton=new JButton(); openButton.setText("写入文件"); openButton //.addActionListener(new java.awt.event.ActionListerner(){ //java.awt.event.ActionListerner cannot be resolved to a type, "ActionListerner"字母写错,改为“ActionListener” .addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e){ File file=new File("word.txt"); try{ FileWriter out=new FileWriter(file); String s=jTextArea.getText(); out.write(s); out.close(); }catch(Exception e1){ e1.printStackTrace(); } } }); } return openButton; } private JButton getCloseButton(){ if(closeButton==null){ closeButton=new JButton(); closeButton.setText("读取文件"); closeButton .addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e){ File file=new File("word.txt"); try{ FileReader in=new FileReader(file); char byt[]=new char[1024]; int len=in.read(byt); jTextArea.setText(new String(byt,0,len)); in.close(); }catch(Exception e1){ e1.printStackTrace(); } } }); } return closeButton; } public Ftest(){ super(); initialize(); } private void initialize(){ this.setSize(300,200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } private JPanel getJContentPane(){ if(jContentPane==null){ jContentPane=new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getScrollPane(), BorderLayout.CENTER); jContentPane.add(getControlPanel(),BorderLayout.SOUTH); } return jContentPane; } public static void main(String[] args) { // TODO Auto-generated method stub Ftest thisClass=new Ftest(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } protected JScrollPane getScrollPane(){ if(scrollPane==null){ scrollPane=new JScrollPane(); scrollPane.setViewportView(getJTextArea()); } return scrollPane; } }
相关文章推荐
- NDK: ant 错误 [javah] Exception in thread "main" java.lang.NullPointerException
- 对象数组报错“空指针”:Exception in thread "main" java.lang.NullPointerException
- Exception in thread "main" java.lang.NullPointerException
- Java报错异常-----Exception in thread "main" java.lang.NullPointerException
- hdfs下载文件时出现Exception in thread "main" java.lang.NullPointerException
- 从零开始使用eclipse Ant脚本语言生成.h头文件:[javah] Exception in thread "main" java.lang.NullPointerException
- hdfs下载出现Exception in thread "main" java.lang.NullPointerException
- Exception in thread "main" java.lang.NullPointerException java报空指针异常
- Exception in thread "main" java.lang.NullPointerException问题
- Exception in thread "main" java.lang.NullPointerException
- 全局变量和局部变量重复之this.name.toString());Exception in thread "main" java.lang.NullPointerException
- Exception in thread "main" java.lang.IllegalArgumentException: input == null!
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in Thread "HouseKeeper" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "HouseKeeper" java.lang.NullPointerException
- 项目启动时 Exception in thread "HouseKeeper" java.lang.NullPointerException
- 定时器中实现数据库表数据移动的功能,Exception in thread "Timer-0" isExist java.lang.NullPointerException定时器中线程报错。
- Exception in thread "Timer-0" java.lang.NullPointerException