This question has already been answered:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Awesomium.Core; using Awesomium.Web; using Awesomium.Windows; using Awesomium.ComponentModel; using Awesomium; namespace Mozart_Browser { public partial class Form1 : Form { int max_tab = 0; public Awesomium.Windows.Forms.WebControl[] Browser; System.Uri home = Properties.Settings.Default.home; public Form1() { InitializeComponent(); newTabs(false, new Awesomium.Windows.Forms.WebControl()); } public void newTabs(bool goHome, Awesomium.Windows.Forms.WebControl contlor) { max_tab++; Browser[max_tab] = new Awesomium.Windows.Forms.WebControl(); Browser[max_tab] = contlor; Browser[max_tab].Size = new Size(545, 283); Browser[max_tab].Location = new Point(6, 51); Browser[max_tab].Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top); if (goHome == true) { Browser[max_tab].Source = home; } else { } customTabControl1.TabPages.Add("New Tabs"); customTabControl1.TabPages[max_tab].Controls.Add(Browser[max_tab]); } } } 

Right here

 Browser[max_tab] = new Awesomium.Windows.Forms.WebControl(); 

Writes an error An object reference does not indicate an object instance.

Reported as a duplicate by Athari , DeKaNszn , PashaPash members , awesoon , dlarchikov 2 May '15 at 7:22 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    what to think? address by index to an element of the array, and this error means ...? - Max Zhukov
  • one
    Well, apparently Browser [max_tab] does not exist. Probably you need to create a Browser, and then also increase the number of elements in the Browser array to the desired one. - Chad
  • Here you declare it, but do not create it at all - Chad
  • one
    > And how can I create it then while such talents compete with me in the labor market, I won’t stay without work - DreamChild
  • one
    > I just just started C # to study so you will study it, you see, and stupid questions will disappear. In the meantime, it seems that you are trying to write a program by typing, too lazy to even read the first 20 pages of any book on C # - DreamChild

1 answer 1

You need:

  1. create a Browser [] array object. Objects are created with the new operator.
  2. But that's not all, because you need an array. You are using a static array, although at the same time expanding it dynamically. There are two options - either you create an array of Browser objects with a margin, or you use a dynamic array, for example List.

In the first version it is

 ... Browser = new Awesomium.Windows.Forms.WebControl[10]; //на 10 вкладок ... 

in the second version it is:

 public List<Awesomium.Windows.Forms.WebControl> Browser; ... Browser = new List<Awesomium.Windows.Forms.WebControl>(); ... Browser.add(new Awesomium.Windows.Forms.WebControl()); 

Where do I hope to arrange it?