Retroceder   Foros del Web > Programación para sitios web > .NET

Respuesta
 
Herramientas Desplegado
Antiguo 13-feb-2007, 14:40   #1 (permalink)
lisseth ha deshabilitado el karma
 
Fecha de Ingreso: enero-2007
Mensajes: 78
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!
lisseth está desconectado   Responder Citando
Antiguo 13-feb-2007, 15:52   #2 (permalink)
atlante está en el buen camino
 
Avatar de atlante
 
Fecha de Ingreso: noviembre-2002
Ubicación: Lima
Mensajes: 139
Enviar un mensaje por MSN a atlante
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...
atlante está desconectado   Responder Citando
Antiguo 13-feb-2007, 16:00   #3 (permalink)
lisseth ha deshabilitado el karma
 
Fecha de Ingreso: enero-2007
Mensajes: 78
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!!
lisseth está desconectado   Responder Citando
Antiguo 13-feb-2007, 17:03   #4 (permalink)
xknown está en el buen camino
 
Avatar de xknown
 
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.249
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
xknown está desconectado   Responder Citando
Antiguo 14-feb-2007, 18:11   #5 (permalink)
atlante está en el buen camino
 
Avatar de atlante
 
Fecha de Ingreso: noviembre-2002
Ubicación: Lima
Mensajes: 139
Enviar un mensaje por MSN a atlante
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...
atlante está desconectado   Responder Citando
Antiguo 15-feb-2007, 07:32   #6 (permalink)
lisseth ha deshabilitado el karma
 
Fecha de Ingreso: enero-2007
Mensajes: 78
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.
lisseth está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 09:19.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93