“Cannot be resolved to a type” when attempting to use Scanner

≯℡__Kan透↙ 提交于 2019-11-29 15:01:16

You need to also import the class itself. At the very top of the file, above public class student, you need to add:

import java.util.Scanner;

In addition, I'd like to pose a few more possible corrections:

  • Class names should be PascalCase
  • Your code should have consistent indentation. Ctrl+Shift+F is your friend here.
Monica Antony

Just use import java.util.Scanner; or use import java.util.*;

I tried the code myself and it works. Therefore, it is a configuration problem. Since you tried to import java.util.Scanner, as hexafraction suggested, then I suppose the JRE is not properly configured.

Try :

  • Right clicking your project name -> Click properties -> Click Java Build Path
  • Select the libraries tab
  • Click on add class folder (at the right) then select your Class.

Edit : Even tho it would not really solve the problem, copy the src folder in a new project would probably solve your issue.

Check your code's compilation level by right click your project in eclipse and click properties.

It might point to 1.6 or lower. If it is the case point it to 1.7

This might solve your problem.

I hope it helps.

Right click on your package > Navigate to properties > Click on java build path > Click on libraries tab > Click on add library > Select JRE System library > Click on next > Click on Finish > Click on apply and Close. enter image description here It should work.... I hope so :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!