я создать массив cardImages в классе KartenClassNull ссылка исключение, когда заполнение многомерного массива изображений
public Image[][][] cardImages = new Image[9][][];
Я написал метод, называемый arrbef(), чтобы заполнить его
public void arrbef()
{
this.cardImages[0][0] = new Image[3] { global::WindowsFormsApplication4.Properties.Resources.Card, global::WindowsFormsApplication4.Properties.Resources.CardBack, global::WindowsFormsApplication4.Properties.Resources.CardSet };
this.cardImages[0][1] = new Image[3] { global::WindowsFormsApplication4.Properties.Resources.Card, global::WindowsFormsApplication4.Properties.Resources.CardBack,
etc....
и в моей форме я вызовите метод arrbef и попробуйте его заполнить.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Karten : Form
{
KartenClass karten = new KartenClass();
int standort = 0;
public Karten()
{
InitializeComponent();
KartenClass.karten[0].arrbef();
}
Но когда я нажимаю на кнопку, которая связывает в эту форму, я получаю следующее сообщение об ошибке:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei WindowsFormsApplication4.KartenClass.arrbef() in c:\Users\david.kresse\Documents\Visual Studio 2012\Projects\WindowsFormsApplication5\KartenClass.cs:Zeile 24.
bei WindowsFormsApplication4.Karten..ctor() in c:\Users\david.kresse\Documents\Visual Studio 2012\Projects\WindowsFormsApplication5\Karten.cs:Zeile 22.
bei WindowsFormsApplication4.Start.btnStartGoToKarten_Click(Object sender, EventArgs e) in c:\Users\david.kresse\Documents\Visual Studio 2012\Projects\WindowsFormsApplication5\Start.cs:Zeile 394.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Что я сделал не так? Я сделал то же самое с другим массивом (который был одним из них).
Надеюсь, вы сможете помочь.
Какова длина 'this.cardImages [0]' :)? –
Всегда лучше включить бросок в настройках отладчика. Затем вы можете получить столбец при возникновении проблемы, и вы можете узнать, как отлаживать его самостоятельно. –
Добро пожаловать в переполнение стека! Почти все случаи «NullReferenceException» одинаковы. См. «[Что такое исключение NullReferenceException в .NET?] (Http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)» для некоторых советов. –