“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() ;
java eclipse java.util.scanner
add a comment |
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() ;
java eclipse java.util.scanner
add a comment |
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() ;
java eclipse java.util.scanner
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
java eclipse java.util.scanner
edited Jul 21 '17 at 16:49
Vince Emigh
9,26042456
9,26042456
asked Sep 13 '14 at 2:07
user4036695
16116
16116
add a comment |
add a comment |
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.
yeah i added that . still same issue
– user4036695
Sep 13 '14 at 2:09
Is the JRE'srt.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
add a comment |
up vote
1
down vote
Just use import java.util.Scanner;
or use import java.util.*;
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
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.
1
i tried and it works now. thnx fr help
– user4036695
Sep 13 '14 at 2:33
add a comment |
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.
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
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 :)
add a comment |
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.
yeah i added that . still same issue
– user4036695
Sep 13 '14 at 2:09
Is the JRE'srt.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
add a comment |
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.
yeah i added that . still same issue
– user4036695
Sep 13 '14 at 2:09
Is the JRE'srt.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
add a comment |
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.
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.
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'srt.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
add a comment |
yeah i added that . still same issue
– user4036695
Sep 13 '14 at 2:09
Is the JRE'srt.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
add a comment |
up vote
1
down vote
Just use import java.util.Scanner;
or use import java.util.*;
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
up vote
1
down vote
Just use import java.util.Scanner;
or use import java.util.*;
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
up vote
1
down vote
up vote
1
down vote
Just use import java.util.Scanner;
or use import java.util.*;
Just use import java.util.Scanner;
or use import java.util.*;
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
add a comment |
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
add a comment |
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.
1
i tried and it works now. thnx fr help
– user4036695
Sep 13 '14 at 2:33
add a comment |
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.
1
i tried and it works now. thnx fr help
– user4036695
Sep 13 '14 at 2:33
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
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.
I resolved the issue.Anyhow thnx fr help.
– user4036695
Sep 24 '16 at 19:05
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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 :)
add a comment |
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 :)
add a comment |
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 :)
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 :)
answered Nov 10 at 16:10
Vijay Bhangur
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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