Re: array problem



Thanks. Peter - I understood that in addition to declaring the array I had
to initialize each element also. In an earlier version of my code when I had
only the code you suggest the compiler objected, saying that the array "may
not be initialized" That is why I added the five lines referring to each
element.


"Peter Van Weert" <Peter.VanWeert@xxxxxxxxxxxxxx> wrote in message
news:1150132781.779254@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Can someone tell me what I'm doing wrong or point me to help towards a
solution. Thanks.


//Declare an array "doc"
DefaultStyledDocument[] doc;

//Instantiate and array "doc"
DefaultStyledDocument[] doc = new DefaultStyledDocument[5];


You have declared the variable doc twice. The following is correct:

//Declare and instantiate an array "doc"
DefaultStyledDocument[] doc = new DefaultStyledDocument[5];

or also correct:

//Declare an array "doc"
DefaultStyledDocument[] doc;

//Instantiate the array "doc"
doc = new DefaultStyledDocument[5];

I think (the error message of the compiler is a bit puzzling) this will
solve your problem.

Cheers,
Peter







.



Relevant Pages

  • Re: variable usage
    ... I don't know the length of the array when I am declaring it. ... why I have to initialize the array? ... Redim and Redim Preserve both 'understand' non-initialized arrays, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Setting an inital value in an Array in a Structure
    ... Last week a reply from Tom Shelton helped me with declaring a Structure containing an ... array of a priviously defined structure like so: ... But when trying to initialize one ... I get an "Object reference not set to an instance of an object" error on the line ...
    (microsoft.public.dotnet.languages.vb)
  • Re: variable usage
    ... I don't know the length of the array when I am declaring it. ... why I have to initialize the array? ... But where did you assign a value to arrOutputData? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: DefaultStyledDocument array problem
    ... DefaultStyledDocument. ... You'll have to declare the variable as an array. ... Don't forget you'll need to initialize every element of the array ...
    (comp.lang.java.gui)
  • Re: static array initialization
    ... It is initialized before the program begins execution therefore it ... from this group as to the style/correctness of declaring a static ... The solution is to use a char, in this case "static char option =3D 0" ... variable will be initialize to 0. ...
    (comp.lang.c)