我做了一個類,其中包含一些字符串和整數,在那個類中我做了一個函數來將類中的數據轉換爲可讀的字符串;類中的android函數拋出java.lang.NullPointerException
public String GetConditions() {
String BigString = null;
String eol = System.getProperty("line.separator");
try {
BigString += "Depth: " + ci(Depth) + eol;
and so on...
因爲我必須轉換很多整數,我做了一個額外的函數來將一個整數轉換爲一個字符串;
public String ci(Integer i) {
// convert integer to string
if (i != null) {
String a = new Integer(i).toString();
return a;
} else {
return "n/a";
}
}
這將引發對return a
一個NullPointerException
例外。我對Java很陌生,這可能是一個noob問題...對不起,提前致謝!
投'Integer'到'字符串'甚至不會編譯。 –
教育評論:D –
感謝球員,但我發現問題,我試圖添加一些字符串'null',這一行: String BigString = null; – Lectere