Foros del Web » Programación para mayores de 30 ;) » .NET »

Error al usar list View

Estas en el tema de Error al usar list View en el foro de .NET en Foros del Web. Buenas tarde. Estoy haciendo un código para que me lea un archivo, lo divida en lienas y a cada linea modificar el texto. Hasta que ...
  #1 (permalink)  
Antiguo 13/04/2013, 00:28
 
Fecha de Ingreso: abril-2010
Ubicación: Saltillo Mexico
Mensajes: 83
Antigüedad: 14 años
Puntos: 4
Exclamación Error al usar list View

Buenas tarde.
Estoy haciendo un código para que me lea un archivo, lo divida en lienas y a cada linea modificar el texto.

Hasta que usaba MsgBox para ver los resultados, todo esta perfecto. Pero al momento de querer añadirlos a un list view me manda el siguiente error:

Object reference not set to an instance of an object.

Código Error:
Ver original
  1. System.NullReferenceException was unhandled
  2.   Message=Object reference not set to an instance of an object.
  3.   Source=UNICA - MAYA
  4.   StackTrace:
  5.        at UNICA___MAYA.panel.Proceso_Tick(Object sender, EventArgs e) in C:\Users\AHD\Documents\Visual Studio 2010\Projects\UNICA - MAYA\UNICA - MAYA\panel.vb:line 190
  6.        at System.Windows.Forms.Timer.OnTick(EventArgs e)
  7.        at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
  8.        at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  9.        at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  10.        at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
  11.        at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  12.        at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  13.        at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
  14.        at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
  15.        at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
  16.        at UNICA___MAYA.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
  17.        at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  18.        at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  19.        at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  20.        at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  21.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
  22.        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  23.        at System.Threading.ThreadHelper.ThreadStart()
  24.   InnerException:


Este es mi codigo:

Código vb:
Ver original
  1. 'Funcion split con la forma en PHP, para no confundirme
  2.    Public Function explode(ByRef str As String, ByVal content As String)
  3.         Return Split(content, str)
  4.     End Function
  5.  
  6.      'Funcion para poner el contenido de un archivo en un string
  7.    Public Function get_file_contents(ByVal ruta As String)
  8.  
  9.         Try
  10.             Dim SPath As String = ruta
  11.             Dim sContent As String = vbNullString
  12.  
  13.             With My.Computer.FileSystem
  14.                 ' verifica si existe el path  
  15.                If .FileExists(SPath) Then
  16.                     ' lee todo el contenido  
  17.                    sContent = .ReadAllText(SPath)
  18.                     Return sContent.ToString
  19.                 Else
  20.                     Return "False"
  21.                 End If
  22.             End With
  23.             ' errores  
  24.        Catch ex As Exception
  25.             Return ex.Message.ToString
  26.         End Try
  27.  
  28.  
  29.     End Function
  30.  
  31.     'Funcion para comparar dos archivos y regresar la diferencia
  32.    Public Function notInMirror(ByVal original As String, ByVal mirror As String)
  33.         'Comparar el arhcivo original y el mirror y regresar solo el contenido de original que no está en mirror
  34.        Dim resultado As String = Replace(original, mirror, "")
  35.         Return resultado
  36.     End Function
  37.  
  38.     Private Sub panel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  39.  
  40.              Dim fileOriginal As String = get_file_contents(filePath)
  41.             'Comparar el archivo original con el mirror
  42.            Dim diferencia As String = notInMirror(fileOriginal, get_file_contents(mirrorPath))
  43.             If diferencia = "" Then
  44.             Else
  45.                 Dim lines As Array = explode(vbCrLf, diferencia)
  46.  
  47.                 For Each line In lines
  48.                     Dim campos As String = Replace(line, "|", "','")
  49.                     'En esta siguiente linea marca el error
  50.                    Dim consultaCampos As String = campos.Substring(0, campos.Length - 3)
  51.                     Dim statement As String = "VALORES ENCONTRADOS ('" & consultaCampos & "')"
  52.                    
  53.                     'Cuando uso esto, marca el error
  54.                    'Las columnas son Fecha y Valores
  55.                    Dim item As ListViewItem
  56.                     item = New ListViewItem(Date.Now.ToString)
  57.                     item.SubItems.Add(statement)
  58.  
  59.                     lvActions.Items.Add(item)
  60.  
  61.                     'Cuando uso un mensaje todo esta bien:
  62.                    'MsgBox(statement)
  63.  
  64.                 Next
  65.  
  66.             End If
  67.  
  68.     End Sub
  #2 (permalink)  
Antiguo 14/04/2013, 00:31
Avatar de othix  
Fecha de Ingreso: mayo-2011
Ubicación: Guatemala
Mensajes: 92
Antigüedad: 13 años
Puntos: 9
Respuesta: Error al usar list View

lvActions inicializa este elemento
__________________
"Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas."
  #3 (permalink)  
Antiguo 14/04/2013, 00:48
 
Fecha de Ingreso: abril-2010
Ubicación: Saltillo Mexico
Mensajes: 83
Antigüedad: 14 años
Puntos: 4
Respuesta: Error al usar list View

Cita:
Iniciado por othix Ver Mensaje
lvActions inicializa este elemento
No comprendo a que te refieres con inicializar.... mm, hacer un lvActions.clear() ??

Etiquetas: list, vb, view
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:55.