2012-10-31 29 views
-3

我有一個跟蹤條的這個Scroll事件:爲什麼即時獲取ArgumentOutOfRangeException?

private void trackBar1_Scroll(object sender, EventArgs e) 
     { 

       trackbarCounter++; 
       if (manualDone == true) 
       { 
        myTrackPanelss1.trackBar1.Minimum = 0; 
        myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;     setpicture(myTrackPanelss1.trackBar1.Value); 
        this.pictureBox1.Refresh(); 
       } 
       if (automaticDone == true) 
       { 
        myTrackPanelss1.trackBar1.Minimum = 0; 
        myTrackPanelss1.trackBar1.Maximum = fiAutomatic.Length - 1; 
        long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value]; 
        long res = GetTopLumAmount(tt, 1000); 
        long max = GetHistogramMaximum(tt); 
        GetHistogramAverage(tt); 
        setpicture(myTrackPanelss1.trackBar1.Value); 
        this.pictureBox1.Refresh(); 

            } 

     } 

唯一的例外是在這條線:

long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value]; 

上的TrackBar IM點擊之後,它這一次向右移動在這種情況下,儘可能遠離框架/軌道40,然後在那裏拋出異常。

例外:

指數超出範圍。必須是非負數且小於集合的大小。 參數名稱:索引

現在fiAutomatic變量包含2225個指數法例如在索引[0]我看到:{000001.bmp} 在索引[1]我看到:{000002.bmp} 等。

list_of_histograms是一個包含現在在每個索引中的40個索引我有一個256索引裏面,例如在索引[0]我看到:{[long256]}和我看到索引[0] 256個數字。 然後再次在索引[1]中{[long256]}和另外256個數字等等。

而且跟蹤條值是40

但爲什麼當IM的跟蹤條移動到右側後40幀/圖像及其引發此異常?

這是一個完整的異常消息:

System.ArgumentOutOfRangeException was unhandled 
    Message=Index was out of range. Must be non-negative and less than the size of the collection. 
Parameter name: index 
    Source=mscorlib 
    ParamName=index 
    StackTrace: 
     at System.ThrowHelper.ThrowArgumentOutOfRangeException() 
     at System.Collections.Generic.List`1.get_Item(Int32 index) 
     at Extracting_Frames.Form1.trackBar1_Scroll(Object sender, EventArgs e) in D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\Form1.cs:line 1793 
     at System.Windows.Forms.TrackBar.OnScroll(EventArgs e) 
     at System.Windows.Forms.TrackBar.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.ScrollableControl.WmHScroll(Message& m) 
     at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
     at System.Windows.Forms.UserControl.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) 
     at System.Windows.Forms.Control.DefWndProc(Message& m) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.TrackBar.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.Run(Form mainForm) 
     at Extracting_Frames.Program.Main() in D:\C-Sharp\Extracting_Frames\Extracting_Frames\Extracting_Frames\Program.cs:line 18 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) 
     at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 
     at System.Activator.CreateInstance(ActivationContext activationContext) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 
+6

因爲在40個元素的數組索引是0到39。40不存在。你已經提到你已經查看了索引0,所以*你必須已經知道這個*。 – Jon

回答

1

list_of_histograms is a contain now 40 indexs in each index

這將是你的問題。請記住,當你聲明一些東西時,它會從0開始索引它。因此,40個索引意味着最大值爲39. list_of_histograms[40]會導致錯誤。

編輯:現在我注意到你的問題的評論,當我去重新打它......

+0

這是什麼評論? – Default

+0

@Default Jon對這個問題本身的評論。 – tmesser

相關問題