I just installed Ubuntu 8.04 and I’m taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error:
My code:
import java.util.Scanner;class test { public static void main (String [] args) { Scanner sc = new Scanner(System.in); System.out.println("hi"); } }
The output:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Scanner cannot be resolved to a type
Scanner cannot be resolved to a type
at test.main(test.java:5)
asked Sep 17, 2008 at 3:05
0
The Scanner class is new in Java 5. I do not know what Hardy’s default Java environment is, but it is not Sun’s and therefore may be outdated.
I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.
answered Sep 17, 2008 at 3:08
ThomasThomas
171k46 gold badges351 silver badges467 bronze badges
If you are using a version of Java before 1.5, java.util.Scanner doesn’t exist.
Which version of the JDK is your Eclipse project set up to use?
Have a look at Project, Properties, Java Build Path — look for the ‘JRE System Library’ entry, which should have a version number next to it.
answered Sep 17, 2008 at 3:10
tgdaviestgdavies
9,3614 gold badges34 silver badges40 bronze badges
It could also be that although you are have JDK 1.5 or higher, the project has some specific settings set that tell it to compile as 1.4. You can test this via Project >> Properties >> Java Compiler and ensure the «Compiler Compliance Level» is set to 1.5 or higher.
answered Sep 17, 2008 at 12:18
![]()
Lee TheobaldLee Theobald
8,39112 gold badges48 silver badges58 bronze badges
I know, It’s quite a while since the question was posted. But the solution may still be of interest to anyone out there. It’s actually quite simple…
Under Ubuntu you need to set the java compiler «javac» to use sun’s jdk instead of any other alternative. The difference to some of the answers posted so far is that I am talking about javac NOT java. To do so fire up a shell and do the following:
- As root or sudo type in at command line:
# update-alternatives --config javac
-
Locate the number pointing to sun’s jdk, type in this number, and hit «ENTER».
-
You’re done! From now on you can enjoy java.util.Scanner under Ubuntu.
System.out.println("Say thank you, Mr.");
Scanner scanner = java.util.Scanner(System.in);
String thanks = scanner.next();
System.out.println("Your welcome.");
You imported Scanner but you’re not using it. You’re using Scanner, which requires user inputs. You’re trying to print out one thing, but you’re exposing the your program to the fact that you are going to use your own input, so it decides to print «Hello World» after you give a user input. But since you are not deciding what the program will print, the system gets confused since it doesn’t know what to print. You need something like int a=sc.nextInt(); or String b=sc.nextLine(); and then give your user input. But you said you want Hello World!, so Scanner is redundant.
answered Mar 31, 2020 at 20:42
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input seconds: ");
int num = in.nextInt();
for (int i = 1; i <=num; i++) {
if(i%10==3)
{
System.out.println(i);
}
}
}
}
![]()
csalmhof
1,7922 gold badges17 silver badges24 bronze badges
answered Jun 17, 2021 at 7:37
ailarailar
11 bronze badge
1
How do you import the Java Scanner class?
There are two ways to implement the Java Scanner import: explicitly reference the java.util.Scanner package and class in the import, or do a wildcard import of java.util.*.
Here is how the two Java Scanner import options look:
-
import java.util.Scanner; // explicit Scanner import
-
import java.util.*; // wildcard Scanner import
The import statement must occur after the package declaration and before the class declaration.
What does import java.util Scanner mean?
The java.util.Scanner class is one of the first components that new Java developers encounter. To use it in your code, you should import it, although another option is to explicitly reference the package in your code.

There are multiple ways to import the Java Scanner class into your code.
Java’s Scanner class makes it easy to get input from the user, which allows simple programs to quickly become interactive. And a little bit of interactivity always makes learning how to program a computer just a little bit more fun.
However, there is one minor complexity the Java Scanner class add into the software development mix.
In order to use the Java Scanner class in your code, you must either fully reference the java.util package when you call the Scanner, or you must add a Java Scanner import statement at the start of your class.
To keep your code readable and less verbose, a Java Scanner import is recommended.
When you add an import statement to your code, you are telling the Java compiler that you need access to a class that isn’t accessible by default. The java.util.Scanner import statement at the top of many Java classes means that somewhere in the code, the Scanner class is being used.
| Java user input made easy |
|---|
|
Learn the easiest ways to handle user input in Java, and format any console output with printf.
|
Java Scanner import example
Here’s an example of an application that uses an explicit Java Scanner import so that we can make the program interactive with user input:
package com.mcnz.example; import java.util.Scanner; public class ScannerUserInput { public static void main(String[] args) { // String input with the Java Scanner System.out.println("How old are you?"); Scanner stringScanner = new Scanner(System.in); String age = stringScanner.next(); System.out.println(age + " is a good age to be!"); } }
Why must we import the Java Scanner class?
With no added import statements to your code, your Java app has default access to all of the classes in the java.lang package. This includes classes such as:
- String
- System
- Integer
- Double
- Math
- Exception
- Thread
However, to use any classes in packages other than java.lang in your code, an import is required.
The Scanner class is found in the java.util package, not java.lang.
Since the Scanner class is found outside of java.lang, you must either directly reference the java.util package every time you use the Scanner, or just add a single Scanner import statement to your Java file.
How do you use the Java Scanner without an import?
Here’s an example of how to avoid a Java Scanner import and instead directly reference the package when the Scanner is used:
package com.mcnz.example; // Notice how the Java Scanner import is removed public class ScannerUserInput { public static void main(String[] args) { System.out.println("How old are you?"); // With no Scanner import, an explicit java.util reference is needed java.util.Scanner stringScanner = new java.util.Scanner(System.in); String age = stringScanner.next(); System.out.println(age + " is a good age to be!"); } }
Notice how the code becomes a bit more verbose, as the package reference adds bloat to the line of code where the Scanner is first declared.
Both the Java Scanner import and an explicit package reference are valid options to access the class. Which option a developer chooses comes down to which approach they believe makes their code the most readable and maintainable.
What is a wildcard import in Java?
There are over 100 classes in the java.util package.
When you import the Java scanner with the import java.util.*; statement, you gain access to each class in the java.util package without adding any more import statements.
In contrast, when an explicit Java Scanner import is performed with the import java.util.Scanner; statement, only the Scanner class becomes available to your code. To use other classes in the java.util package, you must add explicit imports of those classes.
For the sake of simplicity, I recommend new developers use the wildcard approach wto import the Java Scanner class. It requires fewer keystrokes and reduces the opportunity to introduce compile-timer errors into your code.
package com.mcnz.example; // This example uses the wildcard import syntax import java.util.*; public class ScannerUserInput { public static void main(String[] args) { // String input with the Java Scanner System.out.println("How old are you?"); Scanner stringScanner = new Scanner(System.in); String age = stringScanner.next(); System.out.println(age + " is a good age to be!"); } }
Furthermore, if you use an IDE such as Eclipse or VS Code, an import formatter will convert wildcards imports to explicit imports when you finish development.
Senior developers find that implicit imports lead to more readable code, and also avoid possible import collisions when a class appears in two separate packages. For example, the Date class exists in both the java.util and java.sql packages, which can lead to a great deal of confusion if an application uses both packages.
Does a wildcard import hurt performance?
Some developer think doing a java.util.*; import might impact the performance of their code because so many classes become available to your program. However, this is not true. The wildcard import simply makes every class in a package available while you develop your app. It has no impact on the size of the application that eventually gets built.
What happens if you don’t import the Scanner?
If you attempt to use the Scanner class but fail to add an import, or don’t explicitly reference the package and the class together, you will encounter the following error:
Error: Scanner cannot be resolved to a type
The “cannot be resolved to a type” compile time error may sound somewhat confusing to a new developer. All it’s saying is that you have referenced a class that is outside of any package referenced through an import statement.
If you get the “Scanner cannot be resolved to a type” error message, just add the Java Scanner import statement to your code, or explicitly reference the package when you use the Scanner class in your code.
You have not assigned any value to the scanner variable, the first step to using a scanner is importing the library, then assigning the scanner a variable like «sc» or «keyboard» (which I use), then assign something the scanner variable.
Step by step breakdown:
You are missing:
import java.util.Scanner;
This is the first step, always remember
Then do this:
Scanner sc = new Scanner(System.in);
Lastly, assign the «sc» to something, either a string or Int variables.
For example:
int number = sc.nextInt();
or:
String x = sc.next();
Note: You need to understand what the scanner variables are for every type of variable you assign for example string or Int.
For String it is:
sc.next();
For Int:
sc.nextInt();
Same goes for double, float…etc, just change the Int to what you want
In the end, your code should look something like this:
import java.util.Scanner;
public class mama {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter desired input");
int input = sc.nextInt();
}
}
You have not assigned any value to the scanner variable, the first step to using a scanner is importing the library, then assigning the scanner a variable like «sc» or «keyboard» (which I use), then assign something the scanner variable.
Step by step breakdown:
You are missing:
import java.util.Scanner;
This is the first step, always remember
Then do this:
Scanner sc = new Scanner(System.in);
Lastly, assign the «sc» to something, either a string or Int variables.
For example:
int number = sc.nextInt();
or:
String x = sc.next();
Note: You need to understand what the scanner variables are for every type of variable you assign for example string or Int.
For String it is:
sc.next();
For Int:
sc.nextInt();
Same goes for double, float…etc, just change the Int to what you want
In the end, your code should look something like this:
import java.util.Scanner;
public class mama {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter desired input");
int input = sc.nextInt();
}
}
Сканер не может быть разрешен по типу
Я только что установил Ubuntu 8.04 и прохожу курс по Java, поэтому я подумал, почему бы не установить IDE во время ее установки. Поэтому я выбираю свою IDE, Eclipse, и делаю очень простую программу Hello World, чтобы убедиться, что все работает без сбоев. Когда я использую сканер для ввода данных пользователем, я получаю очень странную ошибку:
Мой код:
импортировать java.util.Scanner;class test {public static void main (String [] args) {Scanner sc = new Scanner (System.in); System.out.println ("привет"); }}
Выход:
Исключение в потоке "main" java.lang.Error: Неразрешенные проблемы компиляции: Сканер не может быть преобразован в тип Сканер не может быть преобразован в тип в test.main (test.java:5)
Класс Scanner является новым в Java 5. Я не знаю, какая среда Java по умолчанию у Харди, но она не принадлежит Sun и, следовательно, может быть устаревшей.
Я рекомендую установить пакет sun-java6-jdk, чтобы получить самую последнюю версию, а затем сказать Eclipse, чтобы он использовал его.
Создан 17 сен.
Если вы используете версию Java до 1.5, java.util.Scanner не существует.
Какую версию JDK настроен для использования в вашем проекте Eclipse?
Взгляните на Project, Properties, Java Build Path — найдите запись «Системная библиотека JRE», рядом с которой должен быть номер версии.
Создан 17 сен.
Также может случиться так, что, хотя у вас установлен JDK 1.5 или выше, у проекта есть некоторые определенные настройки, которые говорят ему компилироваться как 1.4. Вы можете проверить это через Project >> Properties >> Java Compiler и убедиться, что для параметра Compiler Compliance Level установлено значение 1.5 или выше.
Создан 17 сен.
Я знаю, прошло много времени с момента публикации вопроса. Но решение может быть интересно кому угодно. На самом деле это довольно просто …
В Ubuntu вам нужно настроить java-компилятор javac на использование sun jdk вместо любой другой альтернативы. Разница с некоторыми из опубликованных ответов заключается в том, что я говорю о javac, а не о java. Для этого запустите снаряд и выполните следующие действия:
- Как root или sudo введите в командной строке:
# update-alternatives --config javac
-
Найдите число, указывающее на jdk солнца, введите это число и нажмите «ENTER».
-
Готово! С этого момента вы можете пользоваться java.util.Scanner в Ubuntu.
System.out.println("Say thank you, Mr.");
Scanner scanner = java.util.Scanner(System.in);
String thanks = scanner.next();
System.out.println("Your welcome.");
Вы импортировали сканер, но не используете его. Вы используете сканер, который требует ввода данных пользователем. Вы пытаетесь распечатать одну вещь, но вы подвергаете свою программу тому факту, что собираетесь использовать свой собственный ввод, поэтому она решает напечатать «Hello World» после того, как вы введете ввод пользователя. Но поскольку вы не решаете, что будет печатать программа, система запутается, поскольку не знает, что печатать. Вам нужно что-то вроде int a=sc.nextInt(); or String b=sc.nextLine(); а затем введите свой пользовательский ввод. Но ты сказал, что хочешь Hello World!, поэтому сканер избыточен.
ответ дан 31 мар ’20, в 21:03
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
java
eclipse
ubuntu
or задайте свой вопрос.
Содержание
- Scanner cannot be resolved to a type
- 6 Answers 6
- Java: Unresolved compilation problem
- 10 Answers 10
- Class file uses import but reports Unresolved compilation problems
- Why do I get this error in Java? Exception in thread «main» java.lang.Error: Unresolved compilation problems
- 2 Answers 2
- Exception in thread «main» java.lang.Error: Unresolved compilation problems: JNI4net
- 1 Answer 1
- Related
- Hot Network Questions
- Subscribe to RSS
Scanner cannot be resolved to a type
I just installed Ubuntu 8.04 and I’m taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error:
6 Answers 6
The Scanner class is new in Java 5. I do not know what Hardy’s default Java environment is, but it is not Sun’s and therefore may be outdated.
I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.
If you are using a version of Java before 1.5, java.util.Scanner doesn’t exist.
Which version of the JDK is your Eclipse project set up to use?
Have a look at Project, Properties, Java Build Path — look for the ‘JRE System Library’ entry, which should have a version number next to it.
It could also be that although you are have JDK 1.5 or higher, the project has some specific settings set that tell it to compile as 1.4. You can test this via Project >> Properties >> Java Compiler and ensure the «Compiler Compliance Level» is set to 1.5 or higher.

I know, It’s quite a while since the question was posted. But the solution may still be of interest to anyone out there. It’s actually quite simple.
Under Ubuntu you need to set the java compiler «javac» to use sun’s jdk instead of any other alternative. The difference to some of the answers posted so far is that I am talking about javac NOT java. To do so fire up a shell and do the following:
- As root or sudo type in at command line:
# update-alternatives —config javac
Locate the number pointing to sun’s jdk, type in this number, and hit «ENTER».
Источник
Java: Unresolved compilation problem
What are the possible causes of a «java.lang.Error: Unresolved compilation problem»?
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
10 Answers 10
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:

try to clean the eclipse project
you just try to clean maven by command
and after that following command
and rebuild your project.
Your compiled classes may need to be recompiled from the source with the new jars.
Try running «mvn clean» and then rebuild
The major part is correctly answered by Thorbjørn Ravn Andersen.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & javac or Eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT: Let’s try to split the riddle into three parts:
(1) What is the meaning of «java.lang.Error: Unresolved compilation problem»
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created by maven (assuming maven is not configured to used ecj for compilation)?
This could happen either by invoking Maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before Maven proceeds to collect class files into the jar (this is what I meant by «concurrent operation» in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
Again several possibilities: (a) compilers don’t agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
Источник
Class file uses import but reports Unresolved compilation problems
I am having an issue resulting in the «Unresolved compilation problems» error. I have looked at this SO question, as well as this one of the same nature and finally this one again describing the same error.
All three of those describe dealing with compilation errors, but when I compile my project’s class files, either using Maven from inside eclipse, Maven from the command line, or just the javac command, no errors are reported.
We have a custom class, JmxTools, which uses import org.apache.commons.modeler.Registry; Now the source file does not complain about a missing import. 
An answer to a similar question suggests looking at the «Problems» view in eclipse. This shows no errors

So, everything compiles fine, the commons-modeler jar is in my Maven dependencies. Yet when I run my web app and call the page using the JmxTools class I receive the following error stack:
How do I get around this? This is something I have not run into before and the answers to similar questions do not appear to apply to this situation
Following Kayaman’s advice:
- Checked the war file and the commons-modeler jar file is present in WEB-INF/lib
- Moved the commons-modeler jar from from the war to my tomcat’s lib/ folder
- did a fresh clean, then compile, the package from the command line
Unfortunately, none of these helped the situation. I am still receiving the error.
Источник
Why do I get this error in Java? Exception in thread «main» java.lang.Error: Unresolved compilation problems
I constantly get the following error when running this code:
«Exception in thread «main» java.lang.Error: Unresolved compilation problems: linearequationproblem cannot be resolved to a type linearequationproblem cannot be resolved to a type at linearequationproblemredo.main(linearequationproblemredo.java:86)»
2 Answers 2
A class can be instantiated via the constructor . so you need to make linearequationproblem as a constructor like below.

I think you are completely new in Java. A good starting point is Java Tutorials and then move on to Oracle Java Tutorials
This code wont compile and these are the problems:
The class name is lineequation and the constructor name is linearequationproblem, which is not allowed. In Java class name and constructor name should be same, since constructor is a special method for creating the instance of the class and initializing the member variables.
Line 56: java linearequationproblem test = new linearequationproblem(in[0], in[1], in[2], in[3], in[4], in[5]); You are trying to create and instance of linearequationproblem but this type (Class) does not exists.
private double f;` That backtick is not legit and will fail to compile, since this is not a correct syntax.
You can refer the docs above for more details about Java. Enjoy Learning !
Источник
Exception in thread «main» java.lang.Error: Unresolved compilation problems: JNI4net
I am working with JNI4net and although the libraries and installed in the build path and eclipse recognizes them, it still gives me run time error. Why could that be in your opinion? Here is the code.
AND here is the message I get!
1 Answer 1
To make your life easier, I am going to share my findings here. Read Martin Serrano’s answer to my question. It will help you understand what needs to be done. Then go to jni4net’s website and download their example zip folder. Extract that. There is an example there called myCSharpDemoCalc. Replace your dll with myCSharpDemoCalc.dll (inside work folder) and then run generateProxies.cmd (be sure to edit this file to your dll name) and run.cmd. Then go to the work folder and run build.cmd (edit name) to create your JAR file. It might not spit out the j4n.dll you probably need to twik the path yourself. Use this JAR file. This was the easiest way to create a JAR file from a third party dll for me.
Hot Network Questions
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник

- Forum
- The Ubuntu Forum Community
- Ubuntu Specialised Support
- Development & Programming
- Programming Talk
- [SOLVED] Scanner cannot be resolved to a type? Java problem in Eclipse
-
[SOLVED] Scanner cannot be resolved to a type? Java problem in Eclipse
I looked at the FAQs and on there is this link on posting homework questions:
http://ubuntuforums.org/showthread.php?t=717011
but on there it says
Just because posting homework assignments is against forum policy, you can ask questions that are related to homework. If you get stuck on certain aspects of the assignment(like compiling your code in Linux, or something not specific to the solution to the problem.
and I feel like my question would warrant that, because all the work I have to do is in a separate class.(Hopefully I’m keeping within the rules here)
My problem isn’t with my code(well maybe it is but it’s compiling fine), but with the Driver class the teacher provided.
I get a similar error to the one this person is having:
http://www.tek-tips.com/viewthread.c…1193576&page=1
and my error is:
Exception in thread «main» java.lang.Error: Unresolved compilation problems:
Scanner cannot be resolved to a type
Scanner cannot be resolved to a typeat ScrabbleDriver.main(ScrabbleDriver.java:8)
The class starts with
Code:
import java.util.*;
at the top and this worked on Dr. Java the compiler I used in Windows, but since I went back to 32 bit Ubuntu to get Java applets to work I decided to just wipe Windows and learn how to use Eclipse and use Ubuntu 100% of the time.
I ask a few of my friends who program in Eclipse but they’re all on Windows and they told me it should work fine.
Am I missing something to use the Scanner class?
System76 Serval Performance 4
Ubuntu 11.04 64 Bit
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
Have you tried checking the Java version you are running as mentioned in the link.
Scanner only came out in Java 1.5, so maybe your Eclipse is running an earlier version. If you have got a later version of Java, make sure that Eclipse is «looking» at that version.
Paul
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
please post the output of
Code:
java --version javac --version
Maybe you have the incorrect version of java. Check that you have at least 1.5 Possibly check my sig for installing java
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
please post the output of
Code:java —version
javac —versionThat didn’t work but I ran it with one — instead.
Code:
java -version java version "1.6.0_0" IcedTea6 1.3.1 (6b12-0ubuntu6) Runtime Environment (build 1.6.0_0-b12) javac -version javac 1.6.0_0-internal
I think that’s what you were asking for.
System76 Serval Performance 4
Ubuntu 11.04 64 Bit
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
Sorry was a typo..

I do not find the any other then sun java is just not worth it.
Hint: https://help.ubuntu.com/community/Java <<But I don’t think this is your issue 100%Please post the accual code you are testing with and please use the code/php tags.
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
since it says you have 1.6
go into eclipse.
click window in the toolbar
under window click preferences
open up the java tag
click on compiler
make sure your compiler compliance level is 1.5 or 1.6next click on Installed JREs
you should have something like java-6-sun-1.6.0.10 with a location of
/usr/lib/jvm/java-6-sun-1.6.0.10if not you need to make it so that it does
Give that a try and see what happens
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
/me forgot to read «Scanner cannot be resolved to a type? Java problem in Eclipse»
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
@drubin
I tried going through the steps at the link for
Choosing the default Java to use
but that didn’t work.
Here is the code
PHP Code:
import java.util.*;
import java.io.*;public class
ScrabbleDriver{
public static void main(String args[])
{
try{
Scanner s = new Scanner(System.in);
System.out.println("enter file name, then word size");
String f = s.next();
int size = s.nextInt();
Scrabble scrab = new Scrabble(f,size);
scrab.readLines();
scrab.reportWinner();
}
catch(Exception e)
{System.out.println(e);}
}
}
@shadylookin
Under compiler I can pick 1.3,1.4,5.0, or 6.0.
Under Installed JREs it says
java-1.5.0-gcj-4.3-1.5.0.0
and
/usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0
I ran
Code:
sudo update-java-alternatives -s java-6-sun
but
Code:
java -version java version "1.6.0_0" IcedTea6 1.3.1 (6b12-0ubuntu6) Runtime Environment (build 1.6.0_0-b12)
I guess it doesn’t change for some reason.
System76 Serval Performance 4
Ubuntu 11.04 64 Bit
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
Originally Posted by SilverDragon
@drubin
I tried going through the steps at the link for but that didn’t work.
Here is the code
PHP Code:
import java.util.*;
import java.io.*;public class
ScrabbleDriver{
public static void main(String args[])
{
try{
Scanner s = new Scanner(System.in);
System.out.println("enter file name, then word size");
String f = s.next();
int size = s.nextInt();
Scrabble scrab = new Scrabble(f,size);
scrab.readLines();
scrab.reportWinner();
}
catch(Exception e)
{System.out.println(e);}
}
}
@shadylookin
Under compiler I can pick 1.3,1.4,5.0, or 6.0.
Under Installed JREs it says
java-1.5.0-gcj-4.3-1.5.0.0
and
/usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0
I ran
Code:
sudo update-java-alternatives -s java-6-sun
but
Code:
java -version java version "1.6.0_0" IcedTea6 1.3.1 (6b12-0ubuntu6) Runtime Environment (build 1.6.0_0-b12)
I guess it doesn’t change for some reason.
well we’re getting somewhere. under compliance pick 6.0 I forgot java’s screwed up naming system(1.6 is 6.0)
sudo update-alternatives —config java then select which one you want to use.
Since you said you installed sun java
go into eclipse
window
preferences
java
installed jres
now click addselect stanard vm if that pops up not sure if that will be in your version of eclipse
click browse
go to /usr/lib/jvm/The Appropriate One Probably java-6-sun-1.6.0.10 or similar/Then just make sure you deselect the other JREs and only have this one selected
-
Re: Scanner cannot be resolved to a type? Java problem in Eclipse
@ shadylookin
Your solution seems to have worked

Thank you very much for your help.
@ drubin
Thanks for trying to help me solve my problem. I’m glad you realized the problem was in Eclipse haha

System76 Serval Performance 4
Ubuntu 11.04 64 Bit
Bookmarks
Bookmarks

Posting Permissions
Доброго времени суток.
Компилирую в Eclips
Код
Eclipse SDK Version: 3.5.0 Build id: I20090611-1540 (c) Copyright Eclipse contributors and others 2000, 2009. All rights reserved.
Задача:
Надо прочитать текст из файла и вывести на экран…
Код:
| Java | ||
|
Эклипс подчёркивает «File» и пишет ошибку при компиляции …
Exception in thread «main» java.lang.Error: Unresolved compilation problem:
File cannot be resolved to a type
at Wellcome.main(Wellcome.java:41)
Строка «Scanner in = new Scanner(new File(«c:/new1.txt»));»
Аналогичные траблы встретил с командой
| Java | ||
|
Тут эклипс тоже находит ошибку , только где ???
__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь