Exception in thread “main“ java.lang.Error: Unresolved compilation problems:

Display error as

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Duplicate local variable t1
    The method set() is undefined for the type Thread
    The method get() is undefined for the type Thread
    The method set(String) is undefined for the type Thread
    The method get() is undefined for the type Thread

    at jdbc.TestThreadLocal.main(TestThreadLocal.java:8)

It roughly means:

Repeated local variable t1
For Thread type, the method set()
is not defined, and the get() method of
type Thread is not defined. The method of type Thread is set(String) is not defined
. The get() method of type Thread is not defined.

 

The picture above is as follows:

 

However, this is what I typed against the teacher's instructional video. It doesn't fall into the word. Once compiled, this is the case. I copied the same code on the Internet and there was no error.

As follows: I changed the above t1.set() to a space without falling, there is still a problem

This Nima is really metaphysics

I made a mistake when I hit the phone. I checked a lot of information. I shut down and restarted and created a new package or file

It doesn't work, there are some big guys, please help me answer it, thank you very much

Picture above

 Not to mention, one is the thread problem, I went back to review.

It seems that there is a problem with the call of the ThreadLocal class


I gave up temporarily. Myeclipse hasn't been cracked until now. The hands are low and it is close to open. In 2017, it has a one-month usage period and nothing is done. If you don't learn it for a month, you will be charged.

Considering that it may be the problem of jdk or installation environment, consider brushing a system in the school, test,

package test;

public class JdbcTest {
	public static void main(String[] args) throws Exception {
		final ThreadLocal<String> thr = new ThreadLocal<String>(); 
		
		Thread th = new Thread(){
			 public void run(){
				 thr.set("你好啊 ");
				 System.out.println(" の :"+thr.get());
			 }
			};
		th.start();
		Thread.sleep(2000);
		Thread th22 = new Thread(){
			 public void run(){
				 thr.set("非常不好! ");
				 System.out.println(" w :"+thr.get());
			 }
			};
		th22.start();
	}
}

Reluctant to achieve this function without the same name

Guess you like

Origin blog.csdn.net/weixin_44146025/article/details/107694040