Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error "scanner cannot be resolved to a type"  RSS feed

 
adebari olalekan
Ranch Hand
Posts: 61
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys, am really new to java and bump into some errors
this is my code:



}
}

and am getting this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Scanner cannot be resolved to a type
Scanner cannot be resolved to a type.

thanks
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you written "scanner" instead of "Scanner" in import statement?
 
adebari olalekan
Ranch Hand
Posts: 61
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote:Have you written "scanner" instead of "Scanner" in import statement?
. that was my typing here; i did not infringe on the upper case sensitive rule, the "scanner" just isnt working, i have checked and and rechked and my codes seems to be good but, i dont know whats wrong
 
adebari olalekan
Ranch Hand
Posts: 61
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adebari olalekan wrote:
Tapas Chand wrote:Have you written "scanner" instead of "Scanner" in import statement?
. that was my typing here; i did not infringe on the upper case sensitive rule, the "scanner" just isnt working, i have checked and and rechked and my codes seems to be good but, i dont know whats wrong
; this is another code i wrote to test but still the same error message:

 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is because Scanner class does not have a constructor taking PrintStream as argument.
You should provide InputStream.
 
adebari olalekan
Ranch Hand
Posts: 61
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote:The error is because Scanner class does not have a constructor taking PrintStream as argument.
You should provide InputStream.

am sorry but if you can be more clear on the "inputstream" am still new here
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.in is an InputStream. You can use that as argument while initializing Scanner object.
One more thing...your main method signature is not correct.
main method accepts String[] as argument.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Eclipse? If so, don't try to run code with compiler errors. You should find a red mark against the line with the error; if you click that red mark, you will get a dropdown list of possible corrections. There is a good chance that one will have a green arrow and say, “Change to...”. Clicking that option may sort out your errors.
The Scanner is intended to read things coming in, so it can read from System.in. It does not write anything out, so you cannot use a Scanner to access System.out.
When you get a yellow mark and its says possible resource leak because the Scanner pointing to System.in is not closed, don't believe it and don't try the suggested correction. On the other hand, you must close a Scanner pointing to a file.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!