在vscode中运行Java:";生成失败,是否继续;如果我选择;继续;,它很好用
在vscode中运行Java:“构建失败,是否要继续?”如果选择“继续”,它可以正常工作 这是一个示例的代码:在vscode中运行Java:";生成失败,是否继续;如果我选择;继续;,它很好用,java,visual-studio-code,vscode-debugger,Java,Visual Studio Code,Vscode Debugger,在vscode中运行Java:“构建失败,是否要继续?”如果选择“继续”,它可以正常工作 这是一个示例的代码: package Java.ch11; class MyThread extends Thread{ public void run() { this.setName("sub thread"); for(int i = 0; i < 1000; i +=2) System.out.println("当前线程:"+this+" "+i); } } pu
package Java.ch11;
class MyThread extends Thread{
public void run()
{
this.setName("sub thread");
for(int i = 0; i < 1000; i +=2)
System.out.println("当前线程:"+this+" "+i);
}
}
public class CreateThreadTest{
public static void main(String[] args)
{
MyThread mt = new MyThread();
mt.start();
Thread t = Thread.currentThread();
t.setName("main thread");
System.out.println("当前线程为:"+t);
}
}
包Java.ch11;
类MyThread扩展线程{
公开募捐
{
此.setName(“子线程”);
对于(int i=0;i<1000;i+=2)
System.out.println(“当前线程:"+这是+i);
}
}
公共类CreateThreadTest{
公共静态void main(字符串[]args)
{
MyThread mt=新的MyThread();
mt.start();
Thread t=Thread.currentThread();
t、 设置名称(“主线程”);
System.out.println(“当前线程为:“+t);
}
}
当我运行你的代码时,它给了我这个错误 您的代码中没有错误。这都是关于您的中文字母。它必须是UTF-8编码的。有许多中文字体样式不是UTF-8编码的。上也讨论了这一点 现在你可以试试这段代码 MyThread.java
class MyThread extends Thread {
public void run() {
this.setName("sub thread");
for(int i = 0; i < 1000; i +=2)
System.out.println("Current thread:" +this+ " "+i);
}
}
public class CreateThreadTest {
public static void main(String[] args) {
MyThread mt = new MyThread();
mt.start();
Thread t = Thread.currentThread();
t.setName("main thread");
System.out.println("The current thread is:"+t);
}
}
运行上述代码后,我得到了您想要的输出
The current thread is:Thread[main thread,5,main]
Current thread:Thread[sub thread,5,main] 0
Current thread:Thread[sub thread,5,main] 2
Current thread:Thread[sub thread,5,main] 4
Current thread:Thread[sub thread,5,main] 6
Current thread:Thread[sub thread,5,main] 8
.......
这是因为构建将编译项目中的所有java文件,因此,我认为您的其他java文件存在一些问题,无法通过编译,但这一个可以通过编译,因此如果继续,它仍然可以工作。您可以在“输出”面板上名为“java语言支持”的下拉列表项中获得详细信息。谢谢您r帮助!我已经尝试了你的代码,但情况是我可以通过忽略“构建失败”信息并强制继续来获得所需的输出。但是“构建失败”“信息仍然会出现。我认为这可能与配置lol有关。如果您找到解决方案,请在此处将其作为答案发布,并将其标记为正确答案,可能会对您有所帮助。