2012-04-24 5 views
0

私はC#2010 WEBアプリケーションを使用していました。
次のように私は新しいクラスへのコードの一部を移動:コードの一部をクラスに移動しました。今すぐ実行時エラーが発生する

namespace ShowDiagram1 
{ 
    public class MyDraw : WebForm1 
    { 
     public void DrawPicture() { 
      ... 
      bitmap.Save(Server.MapPath("pic1.jpg"), ImageFormat.Jpeg); 
      Image1.ImageUrl = this.ResolveUrl("pic1.jpg"); 
      ... 
     } 
    } 
} 

を次のようにエラーメッセージがある:

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 85: Image1.ImageUrl = ResolveUrl("pic1.jpg");

pic1.jpgは、前の行で大丈夫作成されます。

Image1はWebForm1の要素です

ありがとうございました。

+4

ImageUrlを設定しようとする前にImage1を初期化していないようです。 Bitmap.Save(... '?)の前の" ... "には何が入りますか? – yoozer8

答えて

1

Image1変数が初期化されていません。これがWebフォームからコピーされたコードの場合、元のWebフォームの ".designer"ファイルに初期化コードが含まれている可能性があります。その変数の解を検索するだけで、必要なコードが見つかります。

+0

WebForm1デザイナーで次のコードが見つかりました:protected global :: System.Web.UI.WebControls.Image Image1; – user993354

関連する問題