如何在java中正确声明和访问3d标签数组? [英] How do I correctly declare and access a 3d label array in java?

查看:157
本文介绍了如何在java中正确声明和访问3d标签数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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}
    }
};







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(
        }
    }
}





当我尝试运行它时,这给了我一个空指针异常,这样做的正确方法是什么?添加到数组中的标签已在程序的早期声明。



循环应该通过Label'feed'的文本值将标签'aaa'分配给c [0] [0] [0],到c [5] [4] [4]。希望这是有道理的。



我试过的:



上面的代码







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


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(
        }
    }
}

推荐答案

我觉得这个

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



应该是一个字符串列表。

在这种情况下,正确的语法是



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

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



你只是忘了说它们是标签。

我知道它很无聊。




[UpDate]

您的问题包含


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


[UpDate]
You question contain

Quote:

循环应该通过Label '费用分配标签'aaa' '的文本值为c [0] [0] [0],c [5] [4] [4]。

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

,看起来像字符串。



建议:使用调试器并检查每个变量是否包含它应该执行的操作。告诉我们错误的位置。



[UpDate]

您创建 labels2D as一个3d数组和相同的 c

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

labels2D.get(0).setText(c[i][j][k]+""); //String.valueOf(



为什么你使用3索引 c 而不是 labels2D


这篇关于如何在java中正确声明和访问3d标签数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆