我在處理代碼中創建了一個自定義對象數組,然後繼續進行初始化。 objectArray[i].siteID = 5;
處理 - 簡單空指針錯誤
我已經花了近2小時試圖找到如何解決這個問題,但語法信息似乎是正確的:但是,由於某種原因,我在碰到一個空指針異常!
代碼:
class TtalkObject{
int siteID = 0;
String URL = "test";
int commentNum = 5;
int averageLength = 5;
}
PFont f;
TtalkObject[] objectArray;
int whatObjectPart = 0;
int whatObject = 0;
void setup()
{
size(300,300);
f=createFont("Arial",16,true);
objectArray = new TtalkObject[50];
for (int i = 0; i < 50; i ++){
objectArray[i].siteID = 5;
objectArray[i].URL = "test";
objectArray[i].commentNum = 10;
objectArray[i].averageLength = 10;
}
}
您是否嘗試過通過你的程序在調試器步進? – 2011-04-28 06:58:40