作者EasyIsBeauty (把握当下)
看板java
标题[问题] 请教一下
时间Thu Mar 2 02:30:59 2006
Exception in thread "main" java.lang.NullPointerException
at Months.<init>(prog2.java:8)
at prog2.main(prog2.java:45)
请问一下
假如执行程式发现这样的讯息是代表哪里出了错误?
谢谢
补上我的程式码(我是初学者.请多包涵^^")
import java.io.*;
class Months {
public String [] Meng;
public String Jan,Feb,Mar,Apr,May,June;
Months() {
Meng [0]= Jan;
Meng [1]= Feb;
Meng [2]= Mar;
Meng [3]= Apr;
Meng [4]= May;
Meng [5]= June;
}
String askMonth(int eng) {
return Meng[eng];
}
String toChinese(String chi) {
if(chi.equals(Jan) == true) {
return "一月";
}
else if(chi.equals(Feb) == true) {
return "二月";
}
else if(chi.equals(Mar) == true) {
return "三月";
}
else if(chi.equals(Apr) == true) {
return "四月";
}
else if(chi.equals(May) == true) {
return "五月";
}
else {
return "六月";
}
}
}
public class prog2 {
public static void main(String[] argv)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Months m = new Months();
int num1;
do {
System.out.println("请输入1~6的数字");
System.out.print("=>");
String str = br.readLine();
num1 = Integer.parseInt(str);
} while ( (num1 < 1) || (num1 > 6) );
int num = num1 - 1;
String rmonth = m.askMonth(num);
System.out.println(rmonth);
System.out.println(m.toChinese(rmonth));
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.138.240.155
※ 编辑: EasyIsBeauty 来自: 140.138.240.155 (03/02 02:33)