[英]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.