14

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

Ahmad Anis
  • 2,322
  • 4
  • 25
  • 54

6 Answers6

15

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

Sabuj Das
  • 287
  • 3
  • 4
  • 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: https://stackoverflow.com/questions/20601845/no-main-class-found-in-netbeans – bc1984adam Mar 03 '20 at 14:14
7

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)

fcdt
  • 2,371
  • 5
  • 14
  • 26
user14095233
  • 81
  • 1
  • 1
3

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.

Frost Metoh
  • 161
  • 1
  • 4
3

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>
Luis Carlos
  • 345
  • 3
  • 10
0

I have solved this. First create a folder > install Jdk in this folder > create a new folder inside your first creating folder > install netbeans second creating folder.

Fahad
  • 1
0

Yep, always check the JDK version and all the libraries the project uses