Содержание
- 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
The exception in thread “main” java.lang.error: unresolved compilation problem: usually occurs due to syntax or typographical errors. Also, you might get the same exception due to using unknown or undefined classes and modules. Surprisingly, this article will let you know about all the possible causes in detail.
Read on to find out the most relevant cause and solve it at the earliest.
Contents
- Why Does Exception in Thread “main” java.lang.error: Unresolved Compilation Problem: Occur?
- – The Class or Module Is Not Imported
- – Using Non-existent Classes
- – A Syntax Error Resulting in Exception in Thread “main” java.lang.error: Unresolved Compilation Problem:
- – A Typographical Error
- How To Fix the Compilation Exception?
- – Import the Necessary Classes and Modules
- – Remove or Replace the Undefined Classes
- – How To Resolve Java Lang Error in Eclipse?
- – Use an Integrated Development Environment (IDE)
- FAQ
- – What Is Unresolved Compilation Problem Java?
- – What Is Exception in Thread Main Java Lang Error?
- Wrapping Up
The unresolved compilation problems occur because of syntax mistakes and typos. Moreover, using unknown or undefined classes and modules throw the same error. Please go through the causes described below to better understand the issues:
– The Class or Module Is Not Imported
If you use a class or module without importing the same in your program, then you’ll get the said java lang error. It indicates that you are instantiating a class or using a module that is unknown to the stated program.
– Using Non-existent Classes
If you use a class that isn’t already defined, then the same exception will pop up on your screen.
– A Syntax Error Resulting in Exception in Thread “main” java.lang.error: Unresolved Compilation Problem:
Even a common syntax error such as a missing or an extra curly bracket “{“ or a semicolon “;” can output the said exception. It includes sending the wrong arguments while calling the functions.
The below example code highlights the above-stated syntax errors:
public class myClass{
public static void main(String[] args){
anotherClass obj2 = new anotherClass();
obj2.myFunc(“Three”)
}
public class anotherClass{
public String myFunc(int num){
System.out.println(“You have entered:” + num);
}
}
– A Typographical Error
Another common cause behind the java lang error can be a typographical error. It usually happens when you code in hurry without realizing that you’ve typed the variable or function name incorrectly.
For example, you will get the above error if you have accidentally called the println() function as pirntln().
How To Fix the Compilation Exception?
Here are the easy-to-implement working solutions to lower your frustration level and resolve the said exception.
– Import the Necessary Classes and Modules
Look for the classes and modules used in your program. Next, import the given classes and modules. The stated simple step will kick away the exception if it is related to the classes and modules.
– Remove or Replace the Undefined Classes
You must remove the code that instantiates the undefined classes. Also, if you intended to call another class, then replacing the class name with a valid class name will work too.
– How To Resolve Java Lang Error in Eclipse?
You can notice the warnings shown in the Eclipse to identify the mistakes and correct them. Consequently, you will resolve the resulting java lang error.
– Use an Integrated Development Environment (IDE)
Using an IDE is the best possible solution to make the java lang error go away. It is because you’ll be notified regarding the typos and syntax errors. Moreover, you’ll be informed about the unknown modules and classes. You can then easily make the corrections and import the required classes or modules.
The above solution will let you skip the double-checking step before executing the code.
FAQ
The following questions might be disturbing you. So, here are the simplest answers to clear your confusion.
– What Is Unresolved Compilation Problem Java?
The above problem tells that there is a compilation error in the code. Although it is a generic error, you can learn more about it through the error description.
– What Is Exception in Thread Main Java Lang Error?
The stated exception tells that an error has occurred in the thread that is running the Java application. You can say that the given exception points towards the location of the error.
Wrapping Up
Now, it’s clear to you that the compilation error pops up due to common coding mistakes. Also, you get the said exception when the compiler isn’t aware of the classes and modules that are being used in your program. Plus, here is the list of fixing procedures obtained from the above article to make the long talk short:
- You should import all the necessary classes and modules in your program
- You should use only valid classes and modules
- Using the IDE can help you in determining and correcting most of the coding mistakes that help in fixing the java lang error
Indeed, the given exception seems to be complicated but it doesn’t demand anything else except for the careful investigation of the code.
- Author
- Recent Posts
Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.