Why im getting exception: ndex was out of range?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
I have the class WireObjectAnimation:
<pre class="lang-cs prettyprint
Code:
<span class="pln using <span class="typ System<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Collections<span class="pun .<span class="typ Generic<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Linq<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Text<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="pln IO<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Windows<span class="pun .<span class="typ Forms<span class="pun ;<span class="pln <br/>using <span class="typ DannyGeneral<span class="pun ;<span class="pln <br/><br/>namespace <span class="typ AnimationEditor<span class="pln <br/><span class="pun {<span class="pln <br/>    <span class="kwd class<span class="pln  <span class="typ WireObjectAnimation<span class="pln <br/>    <span class="pun {<span class="pln <br/>        <span class="kwd private<span class="pln  <span class="typ List<span class="pun <<span class="typ WireObjectCoordinates<span class="pun ><span class="pln  wocl <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ List<span class="pun <<span class="typ WireObjectCoordinates<span class="pun >();<span class="pln <br/><br/>        <span class="kwd private<span class="pln  <span class="typ WireObject<span class="pln  wo1 <span class="pun =<span class="pln  <span class="kwd null<span class="pun ;<span class="pln <br/><br/>        <span class="kwd string<span class="pln  name<span class="pun ;<span class="pln <br/>        <span class="kwd int<span class="pln  ndx<span class="pun ;<span class="pln <br/>        <span class="kwd public<span class="pln  <span class="typ WireObjectAnimation<span class="pun (<span class="kwd string<span class="pln  name<span class="pun ,<span class="typ WireObject<span class="pln  wo<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/><br/>            <span class="kwd this<span class="pun .<span class="pln name <span class="pun =<span class="pln  name<span class="pun ;<span class="pln <br/><br/>            wo1 <span class="pun =<span class="pln  wo<span class="pun ;<span class="pln <br/><br/>            <span class="typ WireObjectCoordinates<span class="pln  woc<span class="pun ;<span class="pln <br/>            woc <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ WireObjectCoordinates<span class="pun (<span class="pln wo<span class="pun .<span class="pln woc<span class="pun );<span class="pln <br/>            wocl<span class="pun .<span class="typ Add<span class="pun (<span class="pln woc<span class="pun );<span class="pln <br/>            ndx <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln <br/><br/>        <span class="pun }<span class="pln <br/><br/><br/><br/><br/><br/>        <span class="kwd public<span class="pln  <span class="kwd void<span class="pln  <span class="typ Save<span class="pun (<span class="kwd string<span class="pln  path <span class="pun ,<span class="pln  <span class="kwd string<span class="pln  fileName <span class="pun ,<span class="pln  <span class="typ PictureBox<span class="pln  pb<span class="pun )<span class="pln  <br/>        <span class="pun {<span class="pln <br/>            <span class="kwd int<span class="pln  framesNumberX <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln <br/>            <span class="kwd int<span class="pln  framesNumberY <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  fn<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  t <span class="pun =<span class="pln  <span class="typ Path<span class="pun .<span class="typ GetFileNameWithoutExtension<span class="pun (<span class="kwd this<span class="pun .<span class="pln name<span class="pun );<span class="pln <br/>            <span class="kwd if<span class="pln  <span class="pun (<span class="typ File<span class="pun .<span class="typ Exists<span class="pun (<span class="pln path <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  <span class="str "DATABASE"<span class="pln  <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  fileName <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  t <span class="pun +<span class="pln  <span class="str ".txt"<span class="pun ))<span class="pln <br/>            <span class="pun {<span class="pln <br/>                <span class="kwd try<span class="pln <br/>                <span class="pun {<span class="pln <br/>                    <span class="kwd string<span class="pln  f <span class="pun =<span class="pln  <span class="typ Path<span class="pun .<span class="typ Combine<span class="pun (<span class="pln path <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  <span class="str "DATABASE"<span class="pln  <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  t <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  fileName<span class="pun );<span class="pln <br/>                    <span class="typ File<span class="pun .<span class="typ Delete<span class="pun (<span class="pln f<span class="pun );<span class="pln <br/>                <span class="pun }<span class="pln <br/>                <span class="kwd catch<span class="pln  <span class="pun (<span class="typ Exception<span class="pln  ex<span class="pun )<span class="pln <br/>                <span class="pun {<span class="pln <br/>                    <span class="typ MessageBox<span class="pun .<span class="typ Show<span class="pun (<span class="str "Error: Could not delete file from disk. Original error: "<span class="pln  <span class="pun +<span class="pln  ex<span class="pun .<span class="typ Message<span class="pun );<span class="pln <br/>                <span class="pun }<span class="pln <br/><br/><br/>                fn <span class="pun =<span class="pln  path <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  <span class="str "DATABASE"<span class="pln  <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  t <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  fileName<span class="pun ;<span class="pln <br/>            <span class="pun }<span class="pln <br/>            <span class="kwd else<span class="pln <br/>            <span class="pun {<span class="pln <br/>                fn <span class="pun =<span class="pln  path <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  <span class="str "DATABASE"<span class="pln  <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  fileName <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  <span class="kwd this<span class="pun .<span class="pln name <span class="pun +<span class="pln  <span class="str ".txt"<span class="pun ;<span class="pln <br/>            <span class="pun }<span class="pln <br/>            <span class="typ OptionsFile<span class="pln  setting_file <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ OptionsFile<span class="pun (<span class="pln fn<span class="pun );<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "File Name"<span class="pun ,<span class="pln  fn<span class="pun );<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "Object Name"<span class="pun ,<span class="pln  fileName<span class="pun );<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "Animation Name"<span class="pun ,<span class="pln  <span class="kwd this<span class="pun .<span class="pln name<span class="pun );<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "picturebox.Width"<span class="pun ,<span class="pln  pb<span class="pun .<span class="typ Width<span class="pun .<span class="typ ToString<span class="pun ());<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "picturebox.Height"<span class="pun ,<span class="pln  pb<span class="pun .<span class="typ Height<span class="pun .<span class="typ ToString<span class="pun ());<span class="pln <br/><br/>            <span class="kwd string<span class="pun []<span class="pln  xFrames <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="kwd string<span class="pun [<span class="pln wocl<span class="pun .<span class="typ Count<span class="pun ];<span class="pln <br/>            <span class="kwd string<span class="pun []<span class="pln  yFrames <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="kwd string<span class="pun [<span class="pln wocl<span class="pun .<span class="typ Count<span class="pun ];<span class="pln <br/><br/>            <span class="kwd string<span class="pln  X<span class="pun =<span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  Y<span class="pun =<span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd for<span class="pln  <span class="pun (<span class="kwd int<span class="pln  i <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln  i <span class="pun <<span class="pln  wocl<span class="pun .<span class="typ Count<span class="pun ;<span class="pln  i<span class="pun ++)<span class="pln <br/>            <span class="pun {<span class="pln <br/>                X  <span class="pun =<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "Frame_X_{0} "<span class="pun ,<span class="pln  i <span class="pun +<span class="pln  <span class="lit 1<span class="pun );<span class="pln <br/>                Y  <span class="pun =<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "Frame_Y_{0} "<span class="pun ,<span class="pln  i <span class="pun +<span class="pln  <span class="lit 1<span class="pun );<span class="pln <br/>                framesNumberX <span class="pun ++;<span class="pln <br/>                framesNumberY <span class="pun ++;<span class="pln <br/>                <span class="kwd for<span class="pln  <span class="pun (<span class="kwd int<span class="pln  j <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln  j <span class="pun <<span class="pln  wocl<span class="pun [<span class="pln i<span class="pun ].<span class="typ Point_X<span class="pun .<span class="typ Count<span class="pun ;<span class="pln  j<span class="pun ++)<span class="pln <br/>                <span class="pun {<span class="pln <br/>                    xFrames<span class="pun [<span class="pln i<span class="pun ]<span class="pln  <span class="pun +=<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "{0},"<span class="pun ,<span class="pln  wocl<span class="pun [<span class="pln i<span class="pun ].<span class="typ Point_X<span class="pun [<span class="pln j<span class="pun ]);<span class="pln <br/>                    yFrames<span class="pun [<span class="pln i<span class="pun ]<span class="pln  <span class="pun +=<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "{0},"<span class="pun ,<span class="pln  wocl<span class="pun [<span class="pln i<span class="pun ].<span class="typ Point_Y<span class="pun [<span class="pln j<span class="pun ]);<span class="pln <br/><br/><br/>                <span class="pun }<span class="pln <br/><br/>                <span class="kwd string<span class="pln  tt <span class="pun =<span class="pln  xFrames<span class="pun [<span class="pln i<span class="pun ].<span class="typ Trim<span class="pun (<span class="str ","<span class="pun .<span class="typ ToCharArray<span class="pun ());<span class="pln <br/>                <span class="kwd string<span class="pln  yy <span class="pun =<span class="pln   yFrames<span class="pun [<span class="pln i<span class="pun ].<span class="typ Trim<span class="pun (<span class="str ","<span class="pun .<span class="typ ToCharArray<span class="pun ());<span class="pln <br/><br/><br/><br/>                 setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="pln X<span class="pun ,<span class="pln  tt<span class="pun );<span class="pln <br/>                 setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="pln Y<span class="pun ,<span class="pln  yy<span class="pun );<span class="pln <br/><br/>            <span class="pun }<span class="pln <br/><br/>            <span class="kwd int<span class="pln  resultX <span class="pun =<span class="pln  framesNumberX <span class="pun /<span class="pln  <span class="lit 2<span class="pun ;<span class="pln <br/>            <span class="kwd int<span class="pln  resultY <span class="pun =<span class="pln  framesNumberY <span class="pun /<span class="pln  <span class="lit 2<span class="pun ;<span class="pln <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "Number Of Frames X"<span class="pun ,<span class="pln  resultX<span class="pun .<span class="typ ToString<span class="pun ());<span class="pln  <br/>            setting_file<span class="pun .<span class="typ SetKey<span class="pun (<span class="str "Number Of Frames Y"<span class="pun ,<span class="pln  resultY<span class="pun .<span class="typ ToString<span class="pun ());<span class="pln <br/><br/><br/><br/><br/><br/><br/><br/>        <span class="pun }<span class="pln <br/><br/><br/>        <span class="kwd public<span class="pln  <span class="kwd void<span class="pln  <span class="typ Load<span class="pun (<span class="kwd string<span class="pln  path<span class="pun ,<span class="kwd string<span class="pln  fileName<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/>            <span class="kwd int<span class="pln  numberofframesX <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln <br/>            <span class="kwd int<span class="pln  numberofframesY <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  framesX <span class="pun =<span class="pln  <span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  framesY <span class="pun =<span class="pln  <span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  X <span class="pun =<span class="pln  <span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  Y <span class="pun =<span class="pln  <span class="str ""<span class="pun ;<span class="pln <br/>            <span class="kwd string<span class="pln  t <span class="pun =<span class="pln  path <span class="pun +<span class="pln  <span class="str "\"<span class="pln  <span class="pun +<span class="pln  fileName<span class="pun ;<span class="pln <br/>            <span class="typ OptionsFile<span class="pln  setting_file <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ OptionsFile<span class="pun (<span class="pln t<span class="pun );<span class="pln <br/>            <span class="kwd string<span class="pln  XX <span class="pun =<span class="pln  setting_file<span class="pun .<span class="typ GetKey<span class="pun (<span class="str "Number Of Frames X"<span class="pun );<span class="pln <br/>            <span class="kwd string<span class="pln  YY <span class="pun =<span class="pln  setting_file<span class="pun .<span class="typ GetKey<span class="pun (<span class="str "Number Of Frames Y"<span class="pun );<span class="pln <br/>            numberofframesX <span class="pun =<span class="pln  <span class="typ Convert<span class="pun .<span class="typ ToInt32<span class="pun (<span class="pln XX<span class="pun );<span class="pln <br/>            numberofframesY <span class="pun =<span class="pln  <span class="typ Convert<span class="pun .<span class="typ ToInt32<span class="pun (<span class="pln YY<span class="pun );<span class="pln <br/><br/><br/>            <span class="kwd for<span class="pln  <span class="pun (<span class="kwd int<span class="pln  i <span class="pun =<span class="pln  <span class="lit 1<span class="pun ;<span class="pln  i <span class="pun <<span class="pln  numberofframesX <span class="pun ;<span class="pln  i<span class="pun ++)<span class="pln <br/>            <span class="pun {<span class="pln <br/>            X  <span class="pun =<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "Frame_X_{0} "<span class="pun ,<span class="pln  i<span class="pun );<span class="pln <br/>            framesX <span class="pun =<span class="pln  setting_file<span class="pun .<span class="typ GetKey<span class="pun (<span class="pln X<span class="pun );<span class="pln <br/>            <span class="typ List<span class="str <string><span class="pln  floatStrings <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ List<span class="str <string><span class="pun (<span class="pln framesX<span class="pun .<span class="typ Split<span class="pun (<span class="kwd new<span class="pln  <span class="kwd char<span class="pun []<span class="pln  <span class="pun {<span class="pln  <span class="str ,<span class="pln  <span class="pun }));<span class="pln <br/>            <span class="typ List<span class="str <float><span class="pln  test <span class="pun =<span class="pln  floatStrings<span class="pun .<span class="typ Select<span class="pun (<span class="pln tempStr <span class="pun =><span class="pln  <span class="pun (<span class="kwd float<span class="pun )<span class="typ Convert<span class="pun .<span class="typ ToDouble<span class="pun (<span class="pln tempStr<span class="pun )).<span class="typ ToList<span class="pun ();<span class="pln  <br/><br/><br/>                wo1<span class="pun .<span class="pln woc<span class="pun .<span class="typ Point_X<span class="pln  <span class="pun =<span class="pln  test<span class="pun ;<span class="pln   <br/><br/>            <span class="pun }<span class="pln <br/>            <span class="kwd for<span class="pln  <span class="pun (<span class="kwd int<span class="pln  i <span class="pun =<span class="pln  <span class="lit 1<span class="pun ;<span class="pln  i <span class="pun <<span class="pln  numberofframesY<span class="pun ;<span class="pln  i<span class="pun ++)<span class="pln <br/>            <span class="pun {<span class="pln <br/>                Y <span class="pun =<span class="pln  <span class="kwd string<span class="pun .<span class="typ Format<span class="pun (<span class="str "Frame_Y_{0} "<span class="pun ,<span class="pln  i<span class="pun );<span class="pln <br/>                framesY <span class="pun =<span class="pln  setting_file<span class="pun .<span class="typ GetKey<span class="pun (<span class="pln Y<span class="pun );<span class="pln <br/>                <span class="typ List<span class="str <string><span class="pln  floatStrings <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ List<span class="str <string><span class="pun (<span class="pln framesY<span class="pun .<span class="typ Split<span class="pun (<span class="kwd new<span class="pln  <span class="kwd char<span class="pun []<span class="pln  <span class="pun {<span class="pln  <span class="str ,<span class="pln  <span class="pun }));<span class="pln <br/>                <span class="typ List<span class="str <float><span class="pln  test <span class="pun =<span class="pln  floatStrings<span class="pun .<span class="typ Select<span class="pun (<span class="pln tempStr <span class="pun =><span class="pln  <span class="pun (<span class="kwd float<span class="pun )<span class="typ Convert<span class="pun .<span class="typ ToDouble<span class="pun (<span class="pln tempStr<span class="pun )).<span class="typ ToList<span class="pun ();<span class="pln <br/>                wo1<span class="pun .<span class="pln woc<span class="pun .<span class="typ Point_Y<span class="pln  <span class="pun =<span class="pln  test<span class="pun ;<span class="pln <br/>            <span class="pun }<span class="pln <br/>        <span class="pun }<span class="pln <br/><br/><br/>        <span class="kwd public<span class="pln  <span class="kwd void<span class="pln  <span class="typ SetFrame<span class="pun (<span class="kwd int<span class="pln  frameNumber<span class="pun ,<span class="pln  <span class="typ WireObjectCoordinates<span class="pln  woc<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/>            wocl<span class="pun [<span class="pln frameNumber<span class="pun ].<span class="typ Set<span class="pun (<span class="pln woc<span class="pun );<span class="pln <br/>        <span class="pun }<span class="pln <br/><br/>        <span class="kwd public<span class="pln  <span class="typ WireObjectCoordinates<span class="pln  <span class="typ GetFrame<span class="pun (<span class="kwd int<span class="pln  frameNumber<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/>            <span class="kwd if<span class="pln  <span class="pun (<span class="pln frameNumber <span class="pun ><span class="pln  wocl<span class="pun .<span class="typ Count<span class="pun )<span class="pln <br/>            <span class="pun {<span class="pln <br/>                <span class="kwd throw<span class="pln  <span class="kwd new<span class="pln  <span class="typ Exception<span class="pun (<span class="str "not allowed!"<span class="pun );<span class="pln <br/>            <span class="pun }<span class="pln <br/><br/>            <span class="kwd if<span class="pln  <span class="pun (<span class="pln frameNumber <span class="pun ==<span class="pln  wocl<span class="pun .<span class="typ Count<span class="pun )<span class="pln <br/>            <span class="pun {<span class="pln <br/>                <span class="typ WireObjectCoordinates<span class="pln  woc<span class="pun ;<span class="pln <br/>                woc <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ WireObjectCoordinates<span class="pun (<span class="pln wocl<span class="pun [<span class="pln wocl<span class="pun .<span class="typ Count<span class="pln  <span class="pun -<span class="pln  <span class="lit 1<span class="pun ]);<span class="pln  <br/><br/>                wocl<span class="pun .<span class="typ Add<span class="pun (<span class="pln woc<span class="pun );<span class="pln <br/>                <span class="kwd return<span class="pln  woc<span class="pun ;<span class="pln <br/>            <span class="pun }<span class="pln <br/>            <span class="kwd else<span class="pln <br/>            <span class="pun {<span class="pln <br/><br/>                <span class="kwd return<span class="pln  wocl<span class="pun [<span class="pln frameNumber<span class="pun ];<span class="pln <br/>            <span class="pun }<span class="pln <br/><br/><br/>        <span class="pun }<span class="pln <br/>    <span class="pun }<span class="pln <br/><span class="pun }<span class="pln <br/>
[/code]
Now when im doing loading the Load function i see the points its loading it good. But then im trying to move the trackBar bar scroll to the right and then im getting the exception. Now thisl ine: wo1.woc.Point_X = test; the woc have 4 indexs and in each
index Point_X and Point_Y are filled with numbers in each index.
In this class i have the functions SetFrame and GetFrame and im using GetFrame in Form1 scroll event of the trackBar:
<pre class="lang-cs prettyprint
Code:
<span class="kwd private<span class="pln  <span class="kwd void<span class="pln  trackBar1_Scroll<span class="pun (<span class="kwd object<span class="pln  sender<span class="pun ,<span class="pln  <span class="typ EventArgs<span class="pln  e<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/><br/>            currentFrameIndex <span class="pun =<span class="pln  trackBar1<span class="pun .<span class="typ Value<span class="pun ;<span class="pln <br/>            textBox1<span class="pun .<span class="typ Text<span class="pln  <span class="pun =<span class="pln  <span class="str "Frame Number : "<span class="pln  <span class="pun +<span class="pln  trackBar1<span class="pun .<span class="typ Value<span class="pun ;<span class="pln <br/>            wireObject1<span class="pun .<span class="pln woc<span class="pun .<span class="typ Set<span class="pun (<span class="pln wireObjectAnimation1<span class="pun .<span class="typ GetFrame<span class="pun (<span class="pln currentFrameIndex<span class="pun ));<span class="pln  <br/>            <span class="typ LoadPictureAt<span class="pun (<span class="pln trackBar1<span class="pun .<span class="typ Value<span class="pun ,<span class="pln  sender<span class="pun );<span class="pln <br/><br/>            button1<span class="pun .<span class="typ Enabled<span class="pln  <span class="pun =<span class="pln  <span class="kwd false<span class="pun ;<span class="pln <br/>            button2<span class="pun .<span class="typ Enabled<span class="pln  <span class="pun =<span class="pln  <span class="kwd false<span class="pun ;<span class="pln <br/>            button3<span class="pun .<span class="typ Enabled<span class="pln  <span class="pun =<span class="pln  <span class="kwd false<span class="pun ;<span class="pln <br/>            button4<span class="pun .<span class="typ Enabled<span class="pln  <span class="pun =<span class="pln  <span class="kwd false<span class="pun ;<span class="pln <br/>            button8<span class="pun .<span class="typ Enabled<span class="pln  <span class="pun =<span class="pln  <span class="kwd false<span class="pun ;<span class="pln <br/>            <span class="typ SaveFormPicutreBoxToBitMapIncludingDrawings<span class="pun ();<span class="pln <br/><br/>            <span class="kwd return<span class="pun ;<span class="pln <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>        <span class="pun }<span class="pln <br/>
[/code]
Now when im moving the trackBar once to the right it should paint the next set of numbers from the Point_X and Point_Y instead its going to the WireObjectCoordinates class and throw there the exception:
<pre class="lang-cs prettyprint
Code:
<span class="pln using <span class="typ System<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Collections<span class="pun .<span class="typ Generic<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Linq<span class="pun ;<span class="pln <br/>using <span class="typ System<span class="pun .<span class="typ Text<span class="pun ;<span class="pln <br/><br/>namespace <span class="typ AnimationEditor<span class="pln <br/><span class="pun {<span class="pln <br/>    <span class="kwd class<span class="pln  <span class="typ WireObjectCoordinates<span class="pln <br/>    <span class="pun {<span class="pln <br/>        <span class="kwd public<span class="pln  <span class="typ List<span class="str <float><span class="pln  <span class="typ Point_X<span class="pln  <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ List<span class="str <float><span class="pun ();<span class="pln <br/>        <span class="kwd public<span class="pln  <span class="typ List<span class="str <float><span class="pln  <span class="typ Point_Y<span class="pln  <span class="pun =<span class="pln  <span class="kwd new<span class="pln  <span class="typ List<span class="str <float><span class="pun ();<span class="pln <br/><br/>        <span class="kwd public<span class="pln  <span class="typ WireObjectCoordinates<span class="pun ()<span class="pln <br/>        <span class="pun {<span class="pln <br/>        <span class="pun }<span class="pln <br/><br/>        <span class="kwd public<span class="pln  <span class="typ WireObjectCoordinates<span class="pun (<span class="typ WireObjectCoordinates<span class="pln  w<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/>            <span class="typ Point_X<span class="pun .<span class="typ AddRange<span class="pun (<span class="pln w<span class="pun .<span class="typ Point_X<span class="pun );<span class="pln <br/>            <span class="typ Point_Y<span class="pun .<span class="typ AddRange<span class="pun (<span class="pln w<span class="pun .<span class="typ Point_Y<span class="pun );<span class="pln <br/>        <span class="pun }<span class="pln <br/><br/>        <span class="kwd public<span class="pln  <span class="kwd void<span class="pln  <span class="typ Set<span class="pun (<span class="typ WireObjectCoordinates<span class="pln  w<span class="pun )<span class="pln <br/>        <span class="pun {<span class="pln <br/>            <span class="kwd for<span class="pln  <span class="pun (<span class="kwd int<span class="pln  i <span class="pun =<span class="pln  <span class="lit 0<span class="pun ;<span class="pln  i <span class="pun <<span class="pln  <span class="typ Point_X<span class="pun .<span class="typ Count<span class="pun ;<span class="pln  i<span class="pun ++)<span class="pln <br/>            <span class="pun {<span class="pln <br/>                <span class="typ Point_X<span class="pun [<span class="pln i<span class="pun ]<span class="pln  <span class="pun =<span class="pln  w<span class="pun .<span class="typ Point_X<span class="pun [<span class="pln i<span class="pun ];<span class="pln <br/>                <span class="typ Point_Y<span class="pun [<span class="pln i<span class="pun ]<span class="pln  <span class="pun =<span class="pln  w<span class="pun .<span class="typ Point_Y<span class="pun [<span class="pln i<span class="pun ];<span class="pln <br/>            <span class="pun }<span class="pln <br/>        <span class="pun }<span class="pln <br/>    <span class="pun }<span class="pln <br/><span class="pun }<span class="pln <br/>
[/code]
The exception is on the line: Point_X = w.Point_X; Point_X contain now 4 indexs from [0] to [3] each index contain a number like 332.0 333.0 334.0 335.0 And w.Point_X contain now only one index [0] and this index have the number 332.0

i just dont understand why the exception is on this line.
The idea is that when im moving the trackBar to the right it should draw the next coordinates from the wo1.woc.Point_Y and wo1.woc.Point_X but i guess i did something wrong in the Load function ? Im not sure why its throwing the exception and its only when
im moving the trackBar to the right once.



System.ArgumentOutOfRangeException was unhandled<br/>
Message=Index was out of range. Must be non-negative and less than the size of the collection.<br/>
Parameter name: index<br/>
Source=mscorlib<br/>
ParamName=index<br/>
StackTrace:<br/>
at System.ThrowHelper.ThrowArgumentOutOfRangeException()<br/>
at System.Collections.Generic.List`1.get_Item(Int32 index)<br/>
at AnimationEditor.WireObjectCoordinates.Set(WireObjectCoordinates w) in D:C-SharpAnimationEditorAnimationEditorWireObjectCoordinates.cs:line 27<br/>
at AnimationEditor.Form1.trackBar1_Scroll(Object sender, EventArgs e) in D:C-SharpAnimationEditorAnimationEditorForm1.cs:line 434<br/>
at System.Windows.Forms.TrackBar.OnScroll(EventArgs e)<br/>
at System.Windows.Forms.TrackBar.WndProc(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br/>
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br/>
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)<br/>
at System.Windows.Forms.Control.WndProc(Message& m)<br/>
at System.Windows.Forms.ScrollableControl.WmHScroll(Message& m)<br/>
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br/>
at System.Windows.Forms.Form.WndProc(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br/>
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br/>
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)<br/>
at System.Windows.Forms.Control.DefWndProc(Message& m)<br/>
at System.Windows.Forms.Control.WndProc(Message& m)<br/>
at System.Windows.Forms.TrackBar.WndProc(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br/>
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br/>
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.Run(Form mainForm)<br/>
at AnimationEditor.Program.Main() in D:C-SharpAnimationEditorAnimationEditorProgram.cs:line 18<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException: <br/>
<hr class="sig danieli

View the full article
 
Back
Top