当前位置: 代码迷 >> J2SE >> NullPointerException还有Linkedlist sort的有关问题
  详细解决方案

NullPointerException还有Linkedlist sort的有关问题

热度:2959   发布时间:2013-02-25 00:00:00.0
NullPointerException还有Linkedlist sort的问题
这个程序要做一个学生信息的GUI程序,可以update的。要做两种sort,ID和name的。
用Collection.sort(myList);做sort会报错,不知道什么原因【囧…… 
随便填一点进sortByID和sortByName想看看能不能运行结果是NullPointerException
求牛人debug啊~~~

这是主程序
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

public class Sherlock extends JFrame
{
private LinkedList<Student> myList = new LinkedList<Student>();

private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton b5;
private JButton b6;
private JButton b7;
private JButton b8;
private JButton b9;

private JTextArea FArea;
private JTextArea SArea;

private JLabel IDLabel;
private JLabel nameLabel;
private JLabel teleLabel;
private JLabel emailLabel;
private JLabel titleLabel;

private JTextField IDField;
private JTextField nameField;
private JTextField teleField;
private JTextField emailField;

private JPanel FPanel;
private JPanel SPanel;

public Sherlock()
{
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new FlowLayout());

titleLabel= new JLabel("Student Contact Information");
titleLabel.setForeground(Color.BLUE);
titleLabel.setFont((new Font("",1,30)));
JPanel titlePanel = new JPanel();

JPanel FPanel = createFPanel();
FPanel.setLayout(new BorderLayout());
JPanel SPanel = createSPanel();
SPanel.setLayout(new BorderLayout());

JTabbedPane tabbedPane = new JTabbedPane();

titlePanel.add(titleLabel);
tabbedPane.addTab("Query Records",FPanel);
tabbedPane.addTab("Update Records",SPanel);

mainPanel.add(titlePanel,BorderLayout.NORTH);
mainPanel.add(tabbedPane,BorderLayout.SOUTH);

add(mainPanel);

firstLoad();
}

public JPanel createFPanel()
{
JPanel FTPanel = new JPanel();
FTPanel.setLayout(new GridLayout(1,5));

FArea = new JTextArea(10,20);

  b1 = new JButton("Load File");
  b2 = new JButton("Sort by ID");
  b3 = new JButton("Sort by Name");
  b4 = new JButton("Clear");
  b5 = new JButton("Exit");

  class DoListener implements ActionListener
  {
public void actionPerformed(ActionEvent e)
{
String actionString = e.getActionCommand();
if (actionString.equals("Load File"))
{
loadFile();
}
if (actionString.equals("Sort by ID"))
{
sortByID();
}
if (actionString.equals("Sort by Name"))
{
sortByName();
}
if (actionString.equals("Clear"))
{
clear();
}
if (actionString.equals("Exit"))
{
System.exit(0);
}
}
}

ActionListener listener = new DoListener();

b1.addActionListener(listener);
b2.addActionListener(listener);
b3.addActionListener(listener);
b4.addActionListener(listener);
b5.addActionListener(listener);

FTPanel.add(b1);
FTPanel.add(b2);
FTPanel.add(b3);
FTPanel.add(b4);
FTPanel.add(b5);

FPanel.add(FTPanel,BorderLayout.NORTH);
  FPanel.add(FArea,BorderLayout.SOUTH);

  return FPanel;
}

public JPanel createSPanel()
{
JPanel STPanel = new JPanel();
STPanel.setLayout(new GridLayout(2,4));

JPanel SBPanel = new JPanel();
SBPanel.setLayout(new GridLayout(1,4));
  相关解决方案