Jump to content

"could not convert undefined or null to object" on Opera


joecool2005

Recommended Posts

Hi,On Internet Explorer and Firefox, I try to display the content of an object and I get this which is normal.

[object Object]
But on my Opera 9, I was not able to display and I got an error.
could not convert undefined or null to object
On Opera 8, it's working fine. Since I upgraded to Opera 9, my code screwed up.What should I do for Opera 9?Thx
Link to comment
Share on other sites

This is an example of my code.

function object1(){  this.item = new Array();  this.item[0] = new object2();}function object2(x,y){  this.x=x;  this.y=y;}var test = new object1(); var test2= new object2();test.item[0].x=test2;alert(test.item[0].x)

On IE, it will display [object Object] and on Opera it wil display."could not convert undefined or null to object"Right now you will not see it by copy and paste the code. It's a little bit hard to create it. But the main idea is when I try to display the content of the array.Thx

Link to comment
Share on other sites

If you don't give a working example then it's hard to come up with a solution. Right now I'm coming up with a solution for the code you posted, so if that's not what you're using then my answer might not apply to your situation.You have object1 creating a new instance of object2. The constructor for object2 has 2 arguments, x and y, but when you create it in object1 you don't send it any arguments. Instead you create an instance of object1, and then a new unrelated instance of object2, and assign the new object2 to the x property of the object2 inside object1. Opera is probably complaining because when object1 gets created and creates a new instance of object2 as items[0], that might come back as null because you're not sending the arguments to the constructor. But then you're trying to access the x property of the new object and assign it the new instance of object2. It's probably complaining because you're trying to access the x property of a null variable, and you can't do that. You can't convert a null variable to an object with an x property. IE might be creating a new object with only an x property when you do the assignment.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...