3

running Java in vscode: "build failed, do you want to continue?" if i choose "proceed", it works fine.this is the bug info

This is the code of an example:

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

this is the workspace/folder info

Lilian G
  • 37
  • 4

2 Answers2

3

When I ran your code it gave me this error.

enter image description here

There is no error in your code. It is all about your Chinese letters. It must be UTF-8 encoded. There are lot Chinese font styles which are not in UTF-8 encoded. It was discussed on here also.

For now you can try this code.

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

CreateThreadTest.java

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

After ran this above code, I have got your desired output

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
.......
Kalana
  • 4,683
  • 6
  • 22
  • 46
  • Thank you for helping! I've tried your code, but the situation is that I can get my desired output by ignoring the "build failed" info and enforce proceeding. But the "build failed" info would still appear. I'm thinking that maybe it is something to do with the configuration lol. – Lilian G May 01 '20 at 04:29
  • If you found solution post it as answer in here and mark it as the correct answer – Kalana May 01 '20 at 06:49
  • [This](https://stackoverflow.com/questions/13239325/how-to-find-reason-of-failed-build-without-any-error-or-warning) might be helpful you. – Kalana May 01 '20 at 07:35
1

it's because the build will compile all the java files in the project, so, I think there are some problems of your other java files as can't pass the compile, but this one can pass the compile, so if you proceed, it will still work. you can get the details in the droplist item named 'Language Support for java' on 'OUTPUT' panel.

Steven
  • 1,012
  • 1
  • 2
  • 7