mc服务器显示javalangnull,从文本文件读取时发生java.lang.NullPointerException

我想存储的ID和问题。

输出应该是:

{285 = Fill in the blank. A Node is generally defined inside another class, making it a(n) ____ class. }

{37 = How would you rate your programming skills?}

这是文本文件里:

258 MC

Question

Fill in the blank. A Node is generally defined inside another class, making it a(n) ____ class.

Answer

Private

Inner

Public

Internal

Selected

2

37 L5

Question

How would you rate your programming skills?

Answer

Excellent

Very good

Good

Not as good as they should be

Poor

Selected

-1

public static void main(String[] args) throws IOException {

try (BufferedReader br = new BufferedReader(new FileReader("questions.txt"))) {

Map < Integer, String > map = new HashMap < Integer, String >();

String line = br.readLine();

while (line != null) {

String[] temp;

temp = line.split(" ");

int id = Integer.parseInt(temp[0]);

line = br.readLine();

line = br.readLine();

String question = line;

line = br.readLine();

line = br.readLine();

while (line.trim() != ("Selected")) {

line = br.readLine();

}

line = br.readLine();

int selected = Integer.parseInt(line);

line = br.readLine();

map.put(id, question);

System.out.println(map);

}

}

}

运行时我得到的代码:

线程“main”java.lang.NullPointerException中的异常 daos.test.main(test.java:47)C:\ Users \ droop \ Desktop \ DSA \ New folder \ dsaCW2Template \ nbproject \ build-impl.xml :1076:执行此行时出现以下 错误: C:\ Users \ droop \ Desktop \ DSA \ New folder \ dsaCW2Template \ nbproject \ build-impl.xml:830:Java返回:1 BUILD FAILED(total时间:0秒)

2017-04-21

Paul

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值