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

Object reference not set to an instance of an object.

Estas en el tema de Object reference not set to an instance of an object. en el foro de .NET en Foros del Web. Saludos, tengo otro problema estoy generando un archivo txt de la siguente forma: Dim strStreamW As Stream Dim strStreamWriter As StreamWriter Dim FilePath As String ...
  #1 (permalink)  
Antiguo 13/02/2007, 15:40
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 3 meses
Puntos: 0
Pregunta Object reference not set to an instance of an object.

Saludos, tengo otro problema estoy generando un archivo txt de la siguente forma:

Dim strStreamW As Stream
Dim strStreamWriter As StreamWriter
Dim FilePath As String

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim filename As String = Server.MapPath("~/_administracion/deudas/errores/" + FilePath)

Dim FilePath As String = Server.MapPath("~/_administracion/deudas/errores/nombreArchivo.txt")
Try
'Se abre el archivo y si no existe se crea
strStreamW = File.OpenWrite(FilePath)
strStreamWriter = New StreamWriter(strStreamW, System.Text.Encoding.UTF8)

If verifica_usuario_existe(codigo) = True Then
insertar_datos(codigo, valor1, valor2)
Else
Genera_Archivo(fecha, codigo, valor1, valor2)
Me.HyperLink1.Visible = True
End If

Catch ex As Exception
Me.Label1.Text = "Error" + ex.Message
Finally
strStreamWriter.Close()
strStreamW.Close()
cn.Close()
End Try

End sub

al correr la aplicacion me sale el siguiente error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 91: Me.Label1Text = "Error" + ex.Message
Line 92: Finally
Line 93: strStreamWriter.Close()
Line 94: strStreamW.Close()
Line 95: cn.Close()

En la linea 93; no se porque y que estoy haciendo mal si antes si me generaba el archivo sin problemas.

Ayuda please!
  #2 (permalink)  
Antiguo 13/02/2007, 16:52
Avatar de atlante  
Fecha de Ingreso: julio-2002
Ubicación: Lima
Mensajes: 140
Antigüedad: 21 años, 9 meses
Puntos: 0
Re: Object reference not set to an instance of an object.

Prueba los siguiente:

strStreamW = new Stream();
__________________
If you look, If you really read between the lines, You will see...
  #3 (permalink)  
Antiguo 13/02/2007, 17:00
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 3 meses
Puntos: 0
Pregunta Re: Object reference not set to an instance of an object.

gracias por contestar, pero en mi codigo que postee donde exactmente coloco esa linea si se toma la molestia de responder le agradeceria mucho, con todo voy a probar colocando donde yo creo que es conveniente pero le agradeceria me confirmara para estar mas segura.
nuevamente gracias!!
  #4 (permalink)  
Antiguo 13/02/2007, 18:03
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 3 meses
Puntos: 7
Re: Object reference not set to an instance of an object.

Probablemente el objeto strStreamWriter no se está creando adecuadamente...

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #5 (permalink)  
Antiguo 14/02/2007, 19:11
Avatar de atlante  
Fecha de Ingreso: julio-2002
Ubicación: Lima
Mensajes: 140
Antigüedad: 21 años, 9 meses
Puntos: 0
Re: Object reference not set to an instance of an object.

Hola =), pon el codigo antes de esta linea:

strStreamW = File.OpenWrite(FilePath)

Espero que funcione.
__________________
If you look, If you really read between the lines, You will see...
  #6 (permalink)  
Antiguo 15/02/2007, 08:32
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 3 meses
Puntos: 0
De acuerdo Re: Object reference not set to an instance of an object.

gracias, pero el problema se soluciono de esta forma:

Dim strStreamW As Stream
Dim strStreamWriter As StreamWriter
Dim FilePath As String

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

FilePath = Server.MapPath("~/_administracion/deudas/errores/nombreArchivo.txt")

el problema era que declaraba 2 veces FilePath.

gracias por contestar.
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 07:40.