私は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の要素です
ありがとうございました。
ImageUrlを設定しようとする前にImage1を初期化していないようです。 Bitmap.Save(... '?)の前の" ... "には何が入りますか? – yoozer8