一道有问题的小java

这是一个考试系统,有一点点令我头痛的小错误.希望有人能帮我

package demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class iodemo2 extends JFrame implements ActionListener{
    JPanel p1,p2,p3,p4;
    JLabel lab;
    JRadioButton r[]=new JRadioButton[4];
    JButton b1,b2,b3,b4;
    String str="";
    //StringTokenizer str_sub;
    File f;
    BufferedReader in;
    public iodemo2() {
        super("考试系统");
        this.setSize(300,180);
        this.setDefaultCloseOperation(3);
        p1=new JPanel();
        p1.add(new JLabel("题目"));
        lab=new JLabel();
        p1.add(lab);
        p2=new JPanel();
        JRadioButton r[]=new JRadioButton[4];
        ButtonGroup rbg=new ButtonGroup();//编组
        for(int i=0;i<4;i++){
            r[i]=new JRadioButton();
            rbg.add(r[i]);
            p2.add(r[i]);
        }
        p3=new JPanel();
        b1=new JButton("上一题");
        b1.setEnabled(false);
        b2=new JButton("下一题");
        p3.add(b1);
        b2.addActionListener(this);
        p3.add(b2);
        p4=new JPanel();
        b3=new JButton("交卷");
        b4=new JButton("查看");
        b4.setEnabled(false);
        p4.add(b3);
        p4.add(b4);
        this.getContentPane().setLayout(new GridLayout(4,1));
        this.getContentPane().add(p1);
        this.getContentPane().add(p2);
        this.getContentPane().add(p3);
        this.getContentPane().add(p4);
        this.setResizable(false);
        File f=new File("/a.txt");
        try {
                    BufferedReader in = new BufferedReader(new FileReader(f));
                    str=in.readLine();
                    StringTokenizer str_sub=new StringTokenizer(str,"#");
                    lab.setText(str_sub.nextToken());
                    for(int i=0;i<4;i++){
                        r[i].setText(str_sub.nextToken());
                    }
                    //str=in.readLine();

                } catch (IOException ex) {
                }

               
        this.setVisible(true);
    }

    public static void main(String[] args) {
        iodemo2 iodemo2 = new iodemo2();
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==b2){
            try {
                /*
                File f=new File("/a.txt");
                BufferedReader in = new BufferedReader(new FileReader(f));
                                         
                if((str=in.readLine())!=null){
               
                    StringTokenizer str_sub = new StringTokenizer(str, "#");
                    this.lab.setText(str_sub.nextToken());
                    for (int i=0; i<4; i++) {
                        this.r[i].setText(str_sub.nextToken());
                    }
                }*/
               Scanner c = new Scanner(f);
               str=c.nextLine();
               StringTokenizer str_sub = new StringTokenizer(str, "#");
                    this.lab.setText(str_sub.nextToken());
                    for (int i=0; i<4; i++) {
                        this.r[i].setText(str_sub.nextToken());
                    }
            }
            catch (IOException ex) {
                javax.swing.JOptionPane.showMessageDialog(null,"有错");
            } 
            catch (NullPointerException ex) {
               javax.swing.JOptionPane.showMessageDialog(null,"空对象");
           }             
            }

        }
   

说我有个空对象,可我是不知道空对象是哪个.我都晕了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值