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









up vote
3
down vote

favorite












when i run following code it shows error that scanner cannot be resolved to type. i checked that jre is installed and version is 1.7 what else do i need to check ? please help.



public class student 

String name;
int rollno;
public void get(String nm, int rno)
name=nm;
rollno=rno;

public void display()
System.out.println("Name of student is :" +name);
System.out.println("Roll no of student is :" +rollno);

public static void main(String args)

int i ;
int r1;
String n1;
student obj= new student[10];
Scanner sc=new Scanner(System.in);
for(i=0;i<10;i++)

obj[i]= new student();


for(i=0;i<10; i++)
System.out.println("Enter name:");
n1=sc.next();
sc.nextLine();
System.out.println("Enter roll no :");
r1=sc.nextInt();


obj[i].get(n1,r1) ;
obj[i].display() ;












share|improve this question



























    up vote
    3
    down vote

    favorite












    when i run following code it shows error that scanner cannot be resolved to type. i checked that jre is installed and version is 1.7 what else do i need to check ? please help.



    public class student 

    String name;
    int rollno;
    public void get(String nm, int rno)
    name=nm;
    rollno=rno;

    public void display()
    System.out.println("Name of student is :" +name);
    System.out.println("Roll no of student is :" +rollno);

    public static void main(String args)

    int i ;
    int r1;
    String n1;
    student obj= new student[10];
    Scanner sc=new Scanner(System.in);
    for(i=0;i<10;i++)

    obj[i]= new student();


    for(i=0;i<10; i++)
    System.out.println("Enter name:");
    n1=sc.next();
    sc.nextLine();
    System.out.println("Enter roll no :");
    r1=sc.nextInt();


    obj[i].get(n1,r1) ;
    obj[i].display() ;












    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      when i run following code it shows error that scanner cannot be resolved to type. i checked that jre is installed and version is 1.7 what else do i need to check ? please help.



      public class student 

      String name;
      int rollno;
      public void get(String nm, int rno)
      name=nm;
      rollno=rno;

      public void display()
      System.out.println("Name of student is :" +name);
      System.out.println("Roll no of student is :" +rollno);

      public static void main(String args)

      int i ;
      int r1;
      String n1;
      student obj= new student[10];
      Scanner sc=new Scanner(System.in);
      for(i=0;i<10;i++)

      obj[i]= new student();


      for(i=0;i<10; i++)
      System.out.println("Enter name:");
      n1=sc.next();
      sc.nextLine();
      System.out.println("Enter roll no :");
      r1=sc.nextInt();


      obj[i].get(n1,r1) ;
      obj[i].display() ;












      share|improve this question















      when i run following code it shows error that scanner cannot be resolved to type. i checked that jre is installed and version is 1.7 what else do i need to check ? please help.



      public class student 

      String name;
      int rollno;
      public void get(String nm, int rno)
      name=nm;
      rollno=rno;

      public void display()
      System.out.println("Name of student is :" +name);
      System.out.println("Roll no of student is :" +rollno);

      public static void main(String args)

      int i ;
      int r1;
      String n1;
      student obj= new student[10];
      Scanner sc=new Scanner(System.in);
      for(i=0;i<10;i++)

      obj[i]= new student();


      for(i=0;i<10; i++)
      System.out.println("Enter name:");
      n1=sc.next();
      sc.nextLine();
      System.out.println("Enter roll no :");
      r1=sc.nextInt();


      obj[i].get(n1,r1) ;
      obj[i].display() ;









      java eclipse java.util.scanner






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 21 '17 at 16:49









      Vince Emigh

      9,26042456




      9,26042456










      asked Sep 13 '14 at 2:07









      user4036695

      16116




      16116






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          6
          down vote













          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.





          share|improve this answer




















          • yeah i added that . still same issue
            – user4036695
            Sep 13 '14 at 2:09










          • Is the JRE's rt.lib on the build path?
            – Andrey Akhmetov
            Sep 13 '14 at 2:10










          • yes it is on build path
            – user4036695
            Sep 13 '14 at 2:24










          • i tried few more things and it works now. thnx fr yr help
            – user4036695
            Sep 13 '14 at 2:33

















          up vote
          1
          down vote













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






          share|improve this answer






















          • I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05

















          up vote
          1
          down vote













          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.






          share|improve this answer


















          • 1




            i tried and it works now. thnx fr help
            – user4036695
            Sep 13 '14 at 2:33

















          up vote
          0
          down vote













          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.



          enter image description here






          share|improve this answer






















          • I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05

















          up vote
          0
          down vote













          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 :)






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25819174%2fcannot-be-resolved-to-a-type-when-attempting-to-use-scanner%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            6
            down vote













            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.





            share|improve this answer




















            • yeah i added that . still same issue
              – user4036695
              Sep 13 '14 at 2:09










            • Is the JRE's rt.lib on the build path?
              – Andrey Akhmetov
              Sep 13 '14 at 2:10










            • yes it is on build path
              – user4036695
              Sep 13 '14 at 2:24










            • i tried few more things and it works now. thnx fr yr help
              – user4036695
              Sep 13 '14 at 2:33














            up vote
            6
            down vote













            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.





            share|improve this answer




















            • yeah i added that . still same issue
              – user4036695
              Sep 13 '14 at 2:09










            • Is the JRE's rt.lib on the build path?
              – Andrey Akhmetov
              Sep 13 '14 at 2:10










            • yes it is on build path
              – user4036695
              Sep 13 '14 at 2:24










            • i tried few more things and it works now. thnx fr yr help
              – user4036695
              Sep 13 '14 at 2:33












            up vote
            6
            down vote










            up vote
            6
            down vote









            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.





            share|improve this answer












            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.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 13 '14 at 2:09









            Andrey Akhmetov

            29.3k45787




            29.3k45787











            • yeah i added that . still same issue
              – user4036695
              Sep 13 '14 at 2:09










            • Is the JRE's rt.lib on the build path?
              – Andrey Akhmetov
              Sep 13 '14 at 2:10










            • yes it is on build path
              – user4036695
              Sep 13 '14 at 2:24










            • i tried few more things and it works now. thnx fr yr help
              – user4036695
              Sep 13 '14 at 2:33
















            • yeah i added that . still same issue
              – user4036695
              Sep 13 '14 at 2:09










            • Is the JRE's rt.lib on the build path?
              – Andrey Akhmetov
              Sep 13 '14 at 2:10










            • yes it is on build path
              – user4036695
              Sep 13 '14 at 2:24










            • i tried few more things and it works now. thnx fr yr help
              – user4036695
              Sep 13 '14 at 2:33















            yeah i added that . still same issue
            – user4036695
            Sep 13 '14 at 2:09




            yeah i added that . still same issue
            – user4036695
            Sep 13 '14 at 2:09












            Is the JRE's rt.lib on the build path?
            – Andrey Akhmetov
            Sep 13 '14 at 2:10




            Is the JRE's rt.lib on the build path?
            – Andrey Akhmetov
            Sep 13 '14 at 2:10












            yes it is on build path
            – user4036695
            Sep 13 '14 at 2:24




            yes it is on build path
            – user4036695
            Sep 13 '14 at 2:24












            i tried few more things and it works now. thnx fr yr help
            – user4036695
            Sep 13 '14 at 2:33




            i tried few more things and it works now. thnx fr yr help
            – user4036695
            Sep 13 '14 at 2:33












            up vote
            1
            down vote













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






            share|improve this answer






















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05














            up vote
            1
            down vote













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






            share|improve this answer






















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05












            up vote
            1
            down vote










            up vote
            1
            down vote









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






            share|improve this answer














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







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 6 '15 at 11:10









            benka

            4,302113958




            4,302113958










            answered Aug 6 '15 at 10:41









            Monica Antony

            113




            113











            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05
















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05















            I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05




            I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05










            up vote
            1
            down vote













            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.






            share|improve this answer


















            • 1




              i tried and it works now. thnx fr help
              – user4036695
              Sep 13 '14 at 2:33














            up vote
            1
            down vote













            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.






            share|improve this answer


















            • 1




              i tried and it works now. thnx fr help
              – user4036695
              Sep 13 '14 at 2:33












            up vote
            1
            down vote










            up vote
            1
            down vote









            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.






            share|improve this answer














            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 6 '15 at 19:19

























            answered Sep 13 '14 at 2:28









            Jean-François Savard

            17.4k53160




            17.4k53160







            • 1




              i tried and it works now. thnx fr help
              – user4036695
              Sep 13 '14 at 2:33












            • 1




              i tried and it works now. thnx fr help
              – user4036695
              Sep 13 '14 at 2:33







            1




            1




            i tried and it works now. thnx fr help
            – user4036695
            Sep 13 '14 at 2:33




            i tried and it works now. thnx fr help
            – user4036695
            Sep 13 '14 at 2:33










            up vote
            0
            down vote













            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.



            enter image description here






            share|improve this answer






















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05














            up vote
            0
            down vote













            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.



            enter image description here






            share|improve this answer






















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05












            up vote
            0
            down vote










            up vote
            0
            down vote









            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.



            enter image description here






            share|improve this answer














            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.



            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 13 '14 at 3:35

























            answered Sep 13 '14 at 3:21









            DeepInJava

            1,193827




            1,193827











            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05
















            • I resolved the issue.Anyhow thnx fr help.
              – user4036695
              Sep 24 '16 at 19:05















            I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05




            I resolved the issue.Anyhow thnx fr help.
            – user4036695
            Sep 24 '16 at 19:05










            up vote
            0
            down vote













            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 :)






            share|improve this answer
























              up vote
              0
              down vote













              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 :)






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                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 :)






                share|improve this answer












                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 :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 16:10









                Vijay Bhangur

                1




                1



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25819174%2fcannot-be-resolved-to-a-type-when-attempting-to-use-scanner%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo