简体   繁体   English

boolean []无法解析为变量

[英]boolean[] cannot be resolved to a variable

In the class SitoEratostenesaTest , I have: 在类SitoEratostenesaTest ,我有:

SitoEratostenesa myObj = new SitoEratostenesa(liczby[x]);

for(i=1; i<ilosc; i++)
{
    if(tab[i])
    {
        System.out.println((i+1)+" jest liczba pierwsza");
    }
    else
    {
        System.out.println((i+1)+" jest liczba zlozona");
    }
}

boolean tab[] was created in class SitoEratostenesa . boolean tab[]在类SitoEratostenesa中创建。 How can I use this table in my condition? 如何在我的状况下使用该表?

You need to use myObj.tab[i] to reference tab[] in you class. 您需要在类中使用myObj.tab[i]引用tab[] It has no reference with out your object. 它没有引用您的对象。

Is SitoEratostenesa.tab static? SitoEratostenesa.tab是静态的吗? If not you'll need to have a reference to an instance of SitoEratostenesa first. 如果不是这样,您首先需要引用SitoEratostenesa的实例。

Assuming that SitoEratostenesa.tab is accessible (public for example) to SitoEratostenesaTest , then the following should work: 假设SitoEratostenesa.tab可以访问(例如公共) SitoEratostenesaTest ,那么以下各项应该起作用:

 if(SitoEratostenesa.tab[i])

If tab isnt static, you'll need to access it by via an instance of SitoEratostenesa: 如果tab不是静态的,则需要通过SitoEratostenesa的实例来访问它:

SitoEratostenesa yourInstance = ...

if(yourInstance.tab[i]) 

try to get the tab array from SitoEratostenesa by using myObj.getTab() and use it like myObj.getTab()[i] for example. 尝试使用myObj.getTab()从SitoEratostenesa获取选项卡数组,并像myObj.getTab()[i]一样使用它。 If it is not there it might be reached directly, which is usually not a good practice, then it is called like myObj.tab[i] . 如果不存在,则可能无法直接到达(通常不是一个好习惯),然后将其称为myObj.tab[i] If none of them are there, then you need to (if you are allowed to) make a getter method returning the tab . 如果它们都不存在,则需要(如果允许)使用getter方法返回tab

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM