[問題] 請教一下
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)
討論串 (同標題文章)
java 近期熱門文章
PTT數位生活區 即時熱門文章