PDA

View Full Version : "No Constructor Found" problem


Mr-JosE
02-04-2009, 09:45 AM
Hi Guys,

I am having a problem using a doNetObject in my script. Below is a function i have made to populate a listView with elements from an array. Thanks to Paul for the great listView tutorial from what it is based.

fn loadArrayFromXML theLV theArrayLV theArray newArrayValues=
(
theArray = newArrayValues
theArrayLV = #()

print theArray as string

for i = 1 to theArray.count do
(
ni = dotNetObject "system.windows.forms.listViewItem" theArray[i]
append theArrayLV ni
)

theLV.items.clear()
theLV.items.addRange theArrayLV
)

However, when i run the script i get a runtime error:

MAXScript MacroScript Error Exception: -- Runtime error: No constructor found which matched argument list: system.windows.forms.listViewItem

I am at a loss to explain why it is happening. I have a very similar function using the same object elsewhere in the script that works fine.

Any help would be appreciated.

Josť

ZeBoxx2
02-04-2009, 11:02 AM
does it give you a line where it says it's throwing an error?

As your code is incomplete, I had to feed it some supposed values.. got no error:


loadArrayFromXML listview_rollout.lv_objects undefined undefined #("one","two","three")

perhaps the values within the array that you pass as the newArrayValues parameter are invalid?

Mr-JosE
02-04-2009, 11:18 AM
The array values i am passing are fine. I have even given the array new values in the function just to make sure, but i still get the same error. I get the error on this line:

ni = dotNetObject "system.windows.forms.listViewItem" theArray[i]

The message seems to indicate that no constructor exists in the loaded assembly but i find that hard to believe.

Mr-JosE
02-04-2009, 11:30 AM
D'oh you are right! The values i am passing in the array ARN'T right. They should be strings and in the XML the test values i am using are integers >.<

I have been staring at it for hours... haha!

But i have a problem that the array i am saving in the xml files do not have quotation marks around the values in the array. And trying to do so makes the xml invalid. This is a problem. Does anyone know a good work around for this? I am using the execute command on the string to convert it into an array.

Gravey
02-04-2009, 11:54 AM
how about: myString = "#(1, 2, 3, 4)"
myArray = filterstring myString "#(), "
-- returns #("1", "2", "3", "4")

Mr-JosE
02-04-2009, 12:09 PM
Genius! Thank you so very much!

LoneRobot
02-04-2009, 12:49 PM
number values are easy to cast into different formats without having to use execute eg -

val = 1
1
val as string
"1"
val as integer
1
val as float
1.0
val as time
1f

you should be able to cast the numerical array into strings when you make your listviewitem -

ni = dotNetObject "system.windows.forms.listViewItem" (theArray[i] as string)

Mr-JosE
02-04-2009, 01:53 PM
I will have a look at that too thanks :)

CGTalk Moderation
02-04-2009, 01:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.