应用程序不断崩溃,隔离存储

时间:2012-12-19 18:29:15

标签: vb.net windows-phone-7 crash

很长一段时间我在一个页面中使用了大约40个复选框和40个按钮。复选框的每个状态都保存在IO中。我创建了另一个页面,其中包含相同数量的复选框和按钮,因此我想到了更快的页面加载。突然......我使用了模拟器......我的应用程序在启动这个大页面时在50%的情况下崩溃了。 (40个复选框+ 40个按钮)我把它分成4页(每个10个复选框+ 10个按钮),但问题一直在发生。第二次启动此页面时出错。实际上,在第1页中,一切都还可以。

System.ArgumentOutOfRangeException is the error  

排队:

  cb11.IsChecked = cbStates(10)

这是代码:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Controls
Partial Public Class Weidersix2
    Inherits PhoneApplicationPage
    Private cbStates As List(Of Boolean)
    ' Constructor
    Public Sub New()
        InitializeComponent()
        cbStates = New List(Of Boolean)()
    End Sub
    Protected Overrides Sub OnNavigatedTo(e As System.Windows.Navigation.NavigationEventArgs)
        MyBase.OnNavigatedTo(e)
        cbStates = DB.readStates()
        If cbStates.Count > 0 Then
            cb11.IsChecked = cbStates(10)
            cb12.IsChecked = cbStates(11)
            cb13.IsChecked = cbStates(12)
            cb14.IsChecked = cbStates(13)
            cb15.IsChecked = cbStates(14)
            cb16.IsChecked = cbStates(15)
            cb17.IsChecked = cbStates(16)
            cb18.IsChecked = cbStates(17)
            cb19.IsChecked = cbStates(18)
            cb20.IsChecked = cbStates(19)
        Else
            If cb11.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb12.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb13.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb14.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb15.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb16.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb17.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb18.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb19.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If
            If cb20.IsChecked = True Then
                cbStates.Add(True)
            Else
                cbStates.Add(False)
            End If

        End If
    End Sub
    Protected Overrides Sub OnNavigatedFrom(e As System.Windows.Navigation.NavigationEventArgs)
        MyBase.OnNavigatedFrom(e)
        DB.saveStates(cbStates)
    End Sub
    Private Sub cb11_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(10) = True
        End If
    End Sub

    Private Sub cb11_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(10) = False
        End If

    End Sub
    Private Sub cb12_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(11) = True
        End If
    End Sub

    Private Sub cb12_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(11) = False
        End If

    End Sub
    Private Sub cb13_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(12) = True
        End If
    End Sub

    Private Sub cb13_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(12) = False
        End If

    End Sub
    Private Sub cb14_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(13) = True
        End If
    End Sub

    Private Sub cb14_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(13) = False
        End If

    End Sub
    Private Sub cb15_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(14) = True
        End If
    End Sub

    Private Sub cb15_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(14) = False
        End If

    End Sub
    Private Sub cb16_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(15) = True
        End If
    End Sub

    Private Sub cb16_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(15) = False
        End If

    End Sub
    Private Sub cb17_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(16) = True
        End If
    End Sub

    Private Sub cb17_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(16) = False
        End If

    End Sub
    Private Sub cb18_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(17) = True
        End If
    End Sub

    Private Sub cb18_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(17) = False
        End If

    End Sub
    Private Sub cb19_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(18) = True
        End If
    End Sub

    Private Sub cb19_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(18) = False
        End If

    End Sub
    Private Sub cb20_Checked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(19) = True
        End If
    End Sub

    Private Sub cb20_Unchecked(sender As Object, e As RoutedEventArgs)
        If cbStates.Count > 0 Then
            cbStates(19) = False
        End If
    End Sub
End Class

1 个答案:

答案 0 :(得分:1)

听起来你没有保存那么多状态。尝试将您的逻辑更改为:

       If cbStates.Count >= 20 Then
        cb11.IsChecked = cbStates(10)

您正在尝试读取不存在的状态。