Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   .NET (http://www.forosdelweb.com/f29/)
-   -   Object reference not set to an instance of an object. (http://www.forosdelweb.com/f29/object-reference-not-set-instance-object-464782/)

lisseth 13/02/2007 15:40

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!

atlante 13/02/2007 16:52

Re: Object reference not set to an instance of an object.
 
Prueba los siguiente:

strStreamW = new Stream();

lisseth 13/02/2007 17:00

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!!

xknown 13/02/2007 18:03

Re: Object reference not set to an instance of an object.
 
Probablemente el objeto strStreamWriter no se está creando adecuadamente...

Saludos

atlante 14/02/2007 19:11

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.

lisseth 15/02/2007 08:32

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.


La zona horaria es GMT -6. Ahora son las 16:00.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.