2017-09-28 38 views
1

我在某些lejos代碼(用於EV3 lego機器人)中找到空指針異常時遇到問題。 下面是類狀態和構造:將行添加到lejos中的LineMap中的空指針異常無法找到

public class Mapper { 

private LineMap CurrentMap; 
private Line[] lines; 
private boolean[] userDrawn; 
private Rectangle boundary = new Rectangle(0, 0, 594, 891); 
private int counter; 

/** 
* Initializes an empty map with just a boundary 
* 
* @author Ben 
*/ 
public Mapper(){ 

    counter = 0; 
    lines = new Line[counter]; 
    userDrawn = new boolean[counter]; 
    CurrentMap = new LineMap(lines,boundary); 

} 

,造成我悲痛

public void addLine(float x1, float y1, float x2, float y2, boolean isUserDrawn){ 
    counter++; 
    Line[] oldLines = lines; 
    boolean[] oldUserDrawn = userDrawn; 
    lines = new Line[counter]; 
    userDrawn = new boolean[counter]; 

    for(int i = 0; i < counter - 1; i++){ 
     lines[i] = oldLines[i]; 
     userDrawn[i] = oldUserDrawn[i]; 
    } 

    lines[counter-1] = new Line(x1,y1,x2,y2); 
    if(isUserDrawn == true){ 
     userDrawn[counter - 1] = true; 
    } 
    else{ 
     userDrawn[counter - 1] = false; 
    } 
    CurrentMap = new LineMap(lines,boundary); 
} 

什麼可能是一個空指針異常的來源任何想法的功能:

回答

0

別擔心,問題不在這個代碼中。並已解決。