开发者

Javascript TypeError: Cannot call method 'getSize' of undefined

I have been working with javascript lately and I am using Chrome (12) Developer tools and I have been getting the error:

Typ开发者_JAVA技巧eError: Cannot call method 'getSize' of undefined.

I have no idea of why this is happening but have isolated the part which seems to be the problem:

    x = 0;
    for(var i=0; i<w; i++){
        for(var j=0; j<h; j++) {
            display.blit(tile[world[x]], [(i * 34), (j * 34)])
            x++;
            }   
    }

the x++; give me the error and when I comment out the code (of x++;) chrome says there are no errors. Display.blit(tile[world[x]], [(i * 34), (j*34)] doesn't seem to have anything to do with the error although I may be wrong.

My question is how to fix this error and why it is happening in the first place.


The problem seems to be that your x exceeds the number of entries you have in your array. So as the entry is undefined you pass it along to your function where you call the getSize method which doesn't exist for undefined.

Without the rest of the script and the values that world and tile have it's hard to say where you went wrong but I would suggest you confirm that there is an entry for each of the calls you are making. If you do know how many entries you have just try alert(x) to see at which x value you get the error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜