2011-01-26 18 views
0

誰かがこのコードを修正する手助けをしてくれますか?私は、次のエラーが発生します:画像をアップロードしようとするとCType NullReferenceExceptionが発生する

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 21: 'Determine the maximum pictureID for this user 
Line 22: Dim results As DataView = CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), DataView) 
Line 23: Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer) 
Line 24: 'Reference the FileUpload control 
Line 25: Dim imageUpload As FileUpload = CType(dvPictureInsert.FindControl("imageUpload"), FileUpload) 

Source File: C:\Users\Collins\Documents\Visual Studio 2005\WebSites\living to please god world\PhotoAdmin\Default.aspx.vb Line: 23 

と赤のエラー行のコード行にある:

Line 23: Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer) 

誰もが、私が見て開始することができますどこのアイデアを持っていますか?

答えて

3

要素の結果(0)が存在しないか、または要素の結果(0)(0)が存在しない可能性があります(前のステートメントが返す結果によって異なります)。

だから、最初のインスタンスのために、それらにctype関数を使用する前に、これらの事を確認してください:

Dim pictureIDJustAdded As Integer 
If results(0) IsNot Nothing AndAlso results(0).Length > 0 Then 
    pictureIDJustAdded = CType(results(0)(0), Integer) 
Else 
    'report error 
End If 
+0

こんにちは助けに感謝を。私は上記のコードを挿入することを示していますか?ここに、 – onfire4JesusCollins

+1

以下の画像アップロードの完全なコードがあります。22行目( 'Dim pictureIDJustAdded As Integer'がコードフラグメントに含まれるようになりました)の後、23行目を置き換えてください。 – Peladao

関連する問題