Autor Beitrag
Peter666
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 26.03.09 17:19 
Hi @all,

ich bekomme immer die Fehlermeldung:

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

Ich konnte das ganze auch auf einen Teil meines Quellcodes begrenzen, finde den Fehler aber nicht. Googeln hat mich bis jetzt auch nicht weiter gebracht.

Weis jemamnd von euch wann diese Exeption geschmissen wird, auser wenn Variablen falsch deklariert wurden?

Vielen Dank und Gruß

Peter666
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Do 26.03.09 17:50 
Hallo und :welcome:

Der Fehler tritt sehr oft auf, auch an Stellen, wo man nicht damit rechnet. Beispiel soll die Prüfung sein, ob in einer TextBox das Zeichen "a" enthalten ist:
ausblenden C#-Quelltext
1:
if (myTextBox.Text.Contains("a"))    // usw.					

Wenn die TextBox noch nicht initialisiert wurde, sodass sie noch nicht einmal einen leeren String enthält, sondern null, könnte diese Exception auftreten.

(Tatsächlich gibt es hier eine ArgumentNullException; aber das Prinzip ist das gleiche.)

Konkreter kann man nur antworten, wenn du konkrete Beispiele bringst. Jürgen
Peter666 Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 26.03.09 18:04 
Hi Jürgen,

ich kann dir mal einen sehr kleinen Ausschnitt von meinem Quellcode posten, ich will ja nicht das Forum zumplatzen bringen.
Da muss der Fehler irgendwo stecken, bis dahinn habe ich den Fehler schon eingekreist. Ich finde ihn aber nicht, suche schon 2 Tage, ich wäre euch sehr verbunden.

ausblenden volle Höhe C#-Quelltext
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:
// GListBoxItem class 
    public class GListBoxItem
    {
        private string _myText;
        private int _myImageIndex;
        // properties 
        public string Text
        {
            get { return _myText; }
            set { _myText = value; }
        }
        public int ImageIndex
        {
            get { return _myImageIndex; }
            set { _myImageIndex = value; }
        }
        //constructor
        public GListBoxItem(string text, int index)
        {
            _myText = text;
            _myImageIndex = index;
        }
        public GListBoxItem(string text) : this(text, -1) { }
        public GListBoxItem() : this("") { }
        public override string ToString()
        {
            return _myText;
        }
    }//End of GListBoxItem class

    // GListBox class 
    public class GListBox : ListBox
    {
        private ImageList _myImageList = new ImageList();
        public ImageList ImageList
        {
            get { return _myImageList; }
            set { _myImageList = value; }
        }
        public GListBox()
        {
            // Set owner draw mode
            this.DrawMode = DrawMode.OwnerDrawFixed;
        }
        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            GListBoxItem item = new GListBoxItem();
            Rectangle bounds = e.Bounds;
            Size imageSize = _myImageList.ImageSize;
            try
            {
                item = (GListBoxItem)Items[e.Index];
                if (item.ImageIndex != -1)
                {
                    ImageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex);
                    e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor),
                        bounds.Left + imageSize.Width, bounds.Top);
                }
                else
                {
                    e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor),
                        bounds.Left, bounds.Top);
                }
            }
            catch
            {
                if (e.Index != -1)
                {
                    e.Graphics.DrawString(Items[e.Index].ToString(), e.Font,
                        new SolidBrush(e.ForeColor), bounds.Left, bounds.Top);
                }
                else
                {
                    e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor),
                        bounds.Left, bounds.Top);
                }
            }
            base.OnDrawItem(e);
        }
    }


Vielen Dank schon mal für die Mühe

Gruß Peter

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Peter666 Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 26.03.09 18:24 
Ich habe den Fehler gefunden, ich überge immer eine Nullreference,

Vielen Dank für die mühe.

Gruß

Peter