Visual Basic.NET - Object reference not set to an instance of an obje

 
Vista:

Object reference not set to an instance of an obje

Publicado por lis (31 intervenciones) el 13/02/2007 22:32:03
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!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Object reference not set to an instance of an o

Publicado por thessen (298 intervenciones) el 14/02/2007 09:47:53
Posiblemente se deba a que se produce un error al instanciar la variable strStreamWriter y, asi, al llegar al finally se produciria ese error ya que no puede ejecutar el método close del mismo. De todas maneras, viendo tu codigo diria que te sobraria utilizar la variable strStreamW ya que el streamWriter puede abrir un fichero a partir de su ruta.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Object reference not set to an instance of an o

Publicado por lis (31 intervenciones) el 14/02/2007 18:20:20
Muchas gracias por contestar, voy a revisar mi codigo tomando en consideracion su respuesta.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar