Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Java
Label[][][] labels2D =
{
    {
        {aaa,aab,aac,aad,aae},{aba,abb,abc,abd,abe},{aca,acb,acc,acd,ace},{ada,adb,adc,add,ade},{aea,aeb,aec,aed,aee}
    },
    {
        {baa,bab,bac,bad,bae},{bba,bbb,bbc,bbd,bbe},{bca,bcb,bcc,bcd,bce},{bda,bdb,bdc,bdd,bde},{bea,beb,bec,bed,bee}
    },
    {
        {caa,cab,cac,cad,cae},{cba,cbb,cbc,cbd,cbe},{cca,ccb,ccc,ccd,cce},{cda,cdb,cdc,cdd,cde},{cea,ceb,cec,ced,cee}
    },
    {
        {daa,dab,dac,dad,dae},{dba,dbb,dbc,dbd,dbe},{dca,dcb,dcc,dcd,dce},{dda,ddb,ddc,ddd,dde},{dea,deb,dec,ded,dee}
    },
    {
        {eaa,eab,eac,ead,eae},{eba,ebb,ebc,ebd,ebe},{eca,ecb,ecc,ecd,ece},{eda,edb,edc,edd,ede},{eea,eeb,eec,eed,eee}
    },
    {
        {faa,fab,fac,fad,fae},{fba,fbb,fbc,fbd,fbe},{fca,fcb,fcc,fcd,fce},{fda,fdb,fdc,fdd,fde},{fea,feb,fec,fed,fee}
    }
};


Java
char c[][][] = disp1.getArray();
for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 5; k++) {
            labels2D.get(0).setText(c[i][j][k]+""); //String.valueOf(
        }
    }
}


This gives me a Null Pointer Exception when I try to run it, What is the proper way to do this? the labels added to the array are already declared earlier in the program.

The loop is supposed to assign Label 'aaa' through Label 'fee''s text value to c[0][0][0], to c[5][4][4]. Hopefully this makes sense.

What I have tried:

The Above code


Java
char c[][][] = disp1.getArray();
for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 5; k++) {
            labels2D.get(0).setText(c[i][j][k]+""); //String.valueOf(
        }
    }
}
Posted
Updated 4-May-16 16:26pm
Comments
Sergey Alexandrovich Kryukov 4-May-16 20:55pm    
Debugger!
—SA

1 solution

I have the feeling that this
Java
{aaa,aab,aac,aad,aae}

is supposed to be a list of strings.
In this case the correct syntax is

Java
{'aaa','aab','aac','aad','aae'}

You simply forgot to say they are labels.
I know it's boring.


[UpDate]
You question contain
Quote:
The loop is supposed to assign Label 'aaa' through Label 'fee''s text value to c[0][0][0], to c[5][4][4].
which look like strings.

Advice: Use the debugger and check that every variable contain what it os supposed to do. Tell us position of error.

[UpDate]
You create labels2D as a 3d array and same for c
Java
labels2D.get(0).setText(c[i][j][k]+""); //String.valueOf(

Why you do you use 3 index for c and not for labels2D ?
 
Share this answer
 
v4
Comments
Member 12503492 4-May-16 22:45pm    
No they reference several Labels like "Private Label aaa; Private Label aab; Private Label aac;..."
Member 12503492 5-May-16 1:19am    
I can't access any of them, [0][0][0] and [1][1][1] etc are all null pointer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900