Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

eclipse - JDK-9 won't let me use Strings: "java.lang.String is ambiguous"?

A week ago, every project I had was working normally, but when I updated my Eclipse to the Oxygen version and installed JDK-9, things have come strange. When I try to use Strings, after some time (more like every time I save the project) the compiler throws me an error for every String in my project.


String type being recognized as an ambiguous class

String error

"The type java.lang.String is ambiguous"

So I've tried importing java.lang.String to see if it fix the error:

After the import

String error and import "The package java.lang is accessible from more than one module: java.base, java.base"

Surprise! ??

It doesn't :(
I've tried searching these messages on Google and SO but I found nothing...
However, the code running in JDK 8 seems to run normally, check it out:

Changing to JDK 8 (1.8.0_72)

JDK 8 fixin' it all (Code is not showing any errors before the Apply because I've applied, and open up the compiler preferences again for the screenshot)

The console error:

Error: Main method not found in class me.mateusakino.ypul.yPuLTester, please define the main method as:
public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

EDIT 1 - Main class

enter image description here

EDIT 5 - Stacktrace of the errors on Edit 4 (workspace/.metadata/.log)

!SESSION 2017-10-13 13:11:39.551 -----------------------------------------------
eclipse.buildId=4.7.1.M20171009-0410
java.version=9
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

This is a continuation of log file C:UsersHomeDesktopDeveloper FoldersJavaOxygen Workspace.metadata.bak_0.log
Created Time: 2017-10-13 13:43:14.245

!ENTRY org.eclipse.core.resources 4 75 2017-10-13 13:43:14.245
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2017-10-13 13:43:14.245
!MESSAGE Errors running builder 'Java Builder' on project 'yPuL'.
!STACK 0
java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.lookup.ModuleBinding$UnNamedModule.canAccess(ModuleBinding.java:71)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:230)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2922)
    at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:108)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.getTypeBinding(ArrayQualifiedTypeReference.java:93)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.internalResolveType(ArrayQualifiedTypeReference.java:107)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1932)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1835)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1525)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:907)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:902)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:514)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:882)
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141)
    at java.base/java.lang.Thread.run(Thread.java:844)

!ENTRY org.eclipse.core.resources 4 2 2017-10-13 13:43:24.691
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.core.resources 4 75 2017-10-13 13:43:24.695
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2017-10-13 13:43:24.695
!MESSAGE Errors running builder 'Java Builder' on project 'yPuL'.
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.core.resources 4 2 2017-10-13 13:43:39.104
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.core.resources 4 75 2017-10-13 13:43:39.110
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2017-10-13 13:43:39.110
!MESSAGE Errors running builder 'Java Builder' on project 'yPuL'.
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.core.resources 4 2 2017-10-13 13:44:37.810
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.lookup.ModuleBinding$UnNamedModule.canAccess(ModuleBinding.java:71)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:230)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2922)
    at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:108)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.getTypeBinding(ArrayQualifiedTypeReference.java:93)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.internalResolveType(ArrayQualifiedTypeReference.java:107)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1932)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1835)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1525)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:907)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:902)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:514)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:882)
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141)
    at java.base/java.lang.Thread.run(Thread.java:844)

!ENTRY org.eclipse.core.resources 4 75 2017-10-13 13:44:37.814
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2017-10-13 13:44:37.814
!MESSAGE Errors running builder 'Java Builder' on project 'yPuL'.
!STACK 0
java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.lookup.ModuleBinding$UnNamedModule.canAccess(ModuleBinding.java:71)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:230)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2922)
    at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:108)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.getTypeBinding(ArrayQualifiedTypeReference.java:93)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.internalResolveType(ArrayQualifiedTypeReference.java:107)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1932)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1835)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1525)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:907)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:902)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:514)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:882)
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141)
    at java.base/java.lang.Thread.run(Thread.java:844)

!ENTRY org.eclipse.core.resources 4 2 2017-10-13 13:44:53.701
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.lookup.ModuleBinding$UnNamedModule.canAccess(ModuleBinding.java:71)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:230)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2922)
    at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.getTypeBinding(QualifiedTypeReference.java:108)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.getTypeBinding(ArrayQualifiedTypeReference.java:93)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
    at org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference.internalResolveType(ArrayQualifiedTypeReference.java:107)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesWithSuspendedTempErrorHandlingPolicy(SourceTypeBinding.java:1932)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1835)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1525)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:907)
    at org.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the screenshot showing all installed Eclipse plug-ins, I see something very fishy: You have two conflicting features installed:

  • Eclipse Java Development Tools - 3.13.1.v20171009-0... - good
  • Eclipse JDT (Java Development Tools) Patch with Java 9 support (BETA) for Oxygen development stream - 1.1.1.v20170826-05... - not good

From my understanding of Patch features in Eclipse, the second (older) feature could possibly override plug-ins from the former (newer) feature. This would mean still after updating to Oxygen.1a (the official release with Java 9 support) you effectively run a beta version several weeks older.

To double check, you may switch to the Plug-ins tab of the Eclipse Installation Details dialog, and search for "jdt".

This observation could easily explain, why you are still affected by bugs that have been fixed well before the release.

Solution: Please try uninstalling the Patch feature (and check back the Configuration

EDIT: More evidence can be seen in the compiler settings, compliance "9 (BETA)" is a clear indication that you are not running the release version of JDT.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...