简体   繁体   English

类型不匹配:在while循环中无法从int转换为boolean

[英]Type mismatch: cannot convert from int to boolean in while loop

I just started learning java, tried to find the answer but I guess I'm not smart enough. 我刚开始学习Java,试图找到答案,但我想我还不够聪明。 I'm trying to write an array which I got from some file into another file. 我正在尝试将我从某个文件获取的数组写入另一个文件。

The problem is when I'm trying to make "while" it's saying cannot convert from int to boolean. 问题是,当我尝试进行“ while”操作时,这表示无法从int转换为boolean。 Can anyone suggest something. 任何人都可以提出一些建议。 Thank you in advance. 先感谢您。 This is what I have : 这就是我所拥有的:

public void savethefile() throws IOException{

File file1= new File("lala.ppm");
FileWriter save=new FileWriter(file1);
save.write(tytul);

while(i){
    save.write(arraycomment[i]);
    i++;
}

save.close();

Presumably i is an int , not a boolean . 大概i是一个int ,而不是boolean Unlike C/C++, this won't be converted to a boolean implicitly. 与C / C ++不同,它不会隐式转换为boolean You must explicitly state your condition as a boolean . 您必须将条件明确声明为boolean

while (i < arraycomment.length) // or some other constant

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

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