Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans IDE 11 cannot access java.lang Fatal Error: Unable to find package java.lang in classpath or bootclasspath

I downloaded netbeans ide 11 and tried to do a sample hello world project but it is giving me error "cannot access java.lang Fatal Error: Unable to find package java.lang in classpath or bootclasspath" I tried some solutions from stack overflow but didnt worked.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author ahmad
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Hello");
    }
    
}

Main error is " cannot access java.lang Fatal Error: Unable to find package java.lang in classpath or bootclasspath

"enter image description here

like image 432
Ahmad Anis Avatar asked Sep 28 '19 09:09

Ahmad Anis


People also ask

Why can't I import a project in NetBeans?

If this problem occurs when importing a project in netbeans then try to create a new project then check the properties of your new created project and match those properties with the project that you imported in my case there was a difference between target of android package version.

How to fix Java fatal error - unable to find?

run the compilation which fails with "Error:java: Fatal Error: Unable to find..." open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong

Why can’t I Find my JDK path on my project?

If you are not sure of your JDK path, run sudo update-java-alternatives -l to list these. Also, make sure you have set a Main Class as an entry point under Project Properties. See: stackoverflow.com/questions/20601845/…


Video Answer


4 Answers

After exiting netbeans edit the config file netbeans.conf using

nano ~/netbeans-11.2/netbeans/etc/netbeans.conf

In the line netbeans_jdkhome edit the path like

netbeans_jdkhome="/usr/lib/jvm/java-11-openjdk-amd64"

(Found at askubuntu.com)

like image 136
user14095233 Avatar answered Oct 21 '22 05:10

user14095233


I also had the same issue. Solved using manually setting the default jdk.

  1. open the netbeans.conf from <install_dir>/netbeans/etc
  2. set the JDK home path for netbeans_jdkhome property

I am using Ubuntu 19.10

like image 32
Sabuj Das Avatar answered Oct 21 '22 04:10

Sabuj Das


After a complete uninstall of my distros Netbeans version, I resorted to installing Netbeans 11 LTS version from the https://netbeans.apache.org/download/nb110/nb110.html into /usr/share/netbeans. This seems to have resolved the issues in the IDE. The program also seems to compile and run faster now.

I was having very similar problems with Netbeans IDE from the Ubunutu/Mint repositories which was still on version 10 the open JDK was version 11. I could not get the IDE to display without errors - but the program would compile and run from the command line fine.

like image 28
Frost Metoh Avatar answered Oct 21 '22 04:10

Frost Metoh


If you're using Maven for the project and OpenJDK the reason could be the way that you define the source and target options in the maven-compiler-plugin. I had a little project build with JDK 1.8 and when I migrated it the maven compiler plugin show me that error. The solution that worked for me was change the format of the java version on the source and target parameters in maven-compiler-plugin definition:

Before:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <compilerArguments>
            <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
        </compilerArguments>
        <showDeprecation>true</showDeprecation>
    </configuration>
</plugin>

After:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>7</source>
        <target>7</target>
        <compilerArguments>
            <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
        </compilerArguments>
        <showDeprecation>true</showDeprecation>
    </configuration>
</plugin>
like image 25
Luis Carlos Avatar answered Oct 21 '22 05:10

Luis Carlos