tags:

views:

76

answers:

2

Hi all.

public static void main(String[] args) throws IOException {
    String st3[]=new String[]{"сто", "двести", "триста", "sdf", "sdfsd", "sdfsd"};
    System.out.println(st3[1]);
}

In second line Netbeans displays an error:

"non-static variable cannot be referenced from a static context".

I know that the problem is in declaring the array. How to declare a STRING array and quickly fill it with data?

Sorry for stupid question and very bad english.

Thanks very much for answers, error resolved. :)

+7  A: 

The problem isn't to do with declaring an array at all. You haven't shown enough code to show what really is wrong with it, but it's not those lines themselves. The array initialization is a little bit long-winded, but it's valid.

Please show a short but complete program which demonstrates the problem.

Which method are these lines in?

Here's a short but complete program which does work:

public class Test {
    public static void main(String[] args) {
        String st3[]=new String[]{"x", "y", "z", "sdf", "sdfsd", "sdfsd"};
        System.out.println(st3[1]);
    }
}
Jon Skeet
A: 

The shortest way to declare and fill in an array:

String[] st3 = {"сто", "двести", "триста", "sdf", "sdfsd", "sdfsd"};
bancer