-2
我不能出去明白這一個...所以我不斷收到異常螺紋Java的矩形陣列90空指針
AWT-EventQueue-0" java.lang.NullPointerException
at MakeFrame.MovementAndObjects.paint(MovementAndObjects.java:285)
錯誤在我的代碼,但沒有空指針,我可以找到!我的矩形後面的數組是公開的,我只是試圖傳遞我無法從中引用的數組簡單對象。
void defineObjects(){
character = new Player("Zander", true, 10, 1, 1, 1, 1, "none", "none");
charRect = new Rectangle(character.charX, character.charY,character.charWidth,character.charHeight);//y==about 500, x= whatever the x is currently set at
floor1 = new Rectangle(-1, 660, 1201, 10);
floor2 = new Rectangle (-1, 550, 1201, 10);
floor3 = new Rectangle(-1, 440, 1201, 10);
floor4 = new Rectangle (-1, 330, 1201, 10);
floor5 = new Rectangle(-1, 220, 1201, 10);
floor6 = new Rectangle (-1, 110, 1201, 10);
wallA = new Rectangle(0,660,-700,12);
wallB = new Rectangle(1182,660,-700,12);
latter[0]=new Rectangle(1120,560,35,101);
latter[1]= new Rectangle(100,450,35,101);
latter[2]=new Rectangle(400,340,35,101);
latter[3]= new Rectangle(20,340,35,101);
latter[4]=new Rectangle(800,230,35,101);
latter[5]= new Rectangle(100,230,35,101);
latter[6]=new Rectangle(600,450,35,101);
latter[7]= new Rectangle(500,120,35,101);
latter[8]=new Rectangle(700,120,35,101);
objectDefine=true;
repaint();
}
@Override
public void paint(Graphics g)
{
super.paint(g);
if(objectDefine)
{
/*==========
=THE FLOORS=
==========*/
latter[0]=latter1;
g.setColor(myBarf);//floor
g.setColor(myBrown);//floor
g.fillRect(floor1.x, floor1.y, floor1.width, floor1.height);
g.fillRect(floor2.x, floor2.y, floor2.width, floor2.height);
g.fillRect(floor3.x, floor3.y, floor3.width, floor3.height);
g.fillRect(floor4.x, floor4.y, floor4.width, floor4.height);
g.fillRect(floor5.x, floor5.y, floor5.width, floor5.height);
g.fillRect(floor6.x, floor6.y, floor6.width, floor6.height);
/*==========
=THE WALLS=
==========*/
g.setColor(Color.red);
g.fillRect(wallA.x,wallA.y,wallA.height,wallA.width);
g.fillRect(wallB.x,wallB.y,wallB.height,wallB.width);
/*===========
=THE lATTERS=
===========*/
for(int i=0; i<=latter.length; i++)
{
g.setColor(myBrown3);
g.fillRect(latter[i].x, latter[i].y, latter[i].width, latter[i].height);<---- this is the bad line of code according the the error message
g.setColor(Color.BLACK);
System.out.println("D1 complete!!!");
for(int j=5; j<=80; j+=15)
{
g.fillRect(latter[i].x+9 ,latter[i].y+j, latter[i].width/2, latter[i].height/10);
}
}
有沒有想過? 我已初始化它幾種不同的方式,這是我試圖當前之一:
public Rectangle[] latter= {
new Rectangle(1120,560,35,101),
new Rectangle(100,450,35,101),
new Rectangle(400,340,35,101),
new Rectangle(20,340,35,101),
new Rectangle(800,230,35,101),
new Rectangle(100,230,35,101),
new Rectangle(600,450,35,101),
new Rectangle(100,230,35,101),
new Rectangle(700,120,35,101)
};
IV也做標準矩形[]後者=新的Rectangle; [8]在分配後
怎麼樣'latter1'?它可以是空嗎? –
所有後者,0-8,都是矩形。我可以給他們打電話的陣列之外,而不是通過引用數組 – Zander
爲什麼ü需要排隊850指數...我只有300行的東西... – Zander