- Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
- Accepted Answer
- Direct link to this answer
- Direct link to this answer
- Direct link to this comment
- Direct link to this comment
- More Answers (1)
- Direct link to this answer
- Direct link to this answer
- how to catch java exception from MATLAB code
- Example (tested on R2014a):
- MATLAB + JNI = error?
- Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
- Accepted Answer
- Direct link to this answer
- Direct link to this answer
- Direct link to this comment
- Direct link to this comment
- More Answers (1)
- Direct link to this answer
- Direct link to this answer
- Why do I receive an error when starting MATLAB which states: Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError;Could not initalize class sun awt Win32FountManager
Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
Accepted Answer
Direct link to this answer
Direct link to this answer
This error indicates that MATLAB is not able to locate or read your MATLAB preferences directory. This could be due to a setting or variable on your system which is causing MATLAB to look for your preferences in a location where you do not have read access.
Typically this happens due to running a configuration script for MATLAB such as ‘config_matlab.sh’ which attempts to set your preferences directory to a non-default location where you do not have read or write access. You should start by removing the portion of the script which sets your environment variable.
This can also be resolved by creating an environment variable to specify your MATLAB preferences directory immediately before starting MATLAB. You should choose a directory where you have both read and write access. The default location is in your home folder. As an example of the command to run before starting MATLAB, see the following:
This command sets your MATLAB preferences directory to be the default directory inside your home folder. Then, on the next line, the command is to launch MATLAB.
1 Comment
Direct link to this comment
Direct link to this comment
The above bit about environment variables is for OS-X/MacOS and for Linux, and assumes that the user is using a shell derived from ksh . However, ksh and derivatives are case sensitive, and the command in them is export rather than Export . Also the second line needs to begin with /
More Answers (1)
Direct link to this answer
Direct link to this answer
I want to report another common reason matlab on linux would be unable to read the preferences file. I often run matlab over a VPN I establish to the head node of a computer cluster. I then use matlab to submit parallel jobs to the compute nodes. Sometimes, I’ll have more than one VPN tunnel established at once- one from a work computer, then later another from my laptop, or maybe from a different work computer. None of my tunnels can see the other’s applications, so I end up running multiple copies of matlab operating out of my same user folder.
If one matlab opens the preference file for writing, perhaps because I made a change to the window arrangement, then when I attempt to open the second matlab through a different terminal, I receive this error.
If this applies to anyone else, the solution is that if you change the preferences in one instance of matlab, reboot this one before trying to open other instances. If you already have multiple instances running when you change the preferences from one instance, the others will stay open, but will throw this error when you try to reboot them.
how to catch java exception from MATLAB code
The ability to access Java exceptions from MATLAB was added in R2012b. If I’m not mistaken, prior versions could only catch exceptions in a general manner without specific error information about the Java error.
Example (tested on R2014a):
try openStream(java.net.URL('http://non.existant')) catch ME end
The exception caught is a MATLAB object that wraps the original Java exception:
>> ME ME = JavaException with properties: ExceptionObject: [1x1 java.net.UnknownHostException] identifier: 'MATLAB:Java:GenericException' message: 'Java exception occurred: java.net.UnknownHostException: non.existant at java.net.AbstractPlainSocketImpl.connect(Unk. ' cause: <> stack: [0x1 struct]
so we can access the entire error stack trace:
>> printStackTrace(ME.ExceptionObject) java.net.UnknownHostException: non.existant at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source)
MATLAB + JNI = error?
Anyone out there used MATLAB’s javaObject() function with a JAR file that uses JNI? I’m trying to get JHDF5 running and it seems like it bombs when it tries to get access using jhdf5.dll so I don’t really know what to do next. 🙁 edit: I am NOT trying to read basic HDF5 files. I have my own custom Java code that does something with HDF5 and needs the JHDF5 library. Also, my first question is just whether anyone has used it successfully at all. If not then I’m probably fighting a losing battle. If so then at least it gives me hope. I’ll try to debug, it’s very difficult compared to debugging regular Java code under Eclipse. update: ok, specifics below. I made a very short test class and it has the same failure modes as my complicated program. It looks like my Java classes can’t access the HDF5 static constants for some reason. My MATLAB javaclasspath is set to include my test-hdf5.jar with Test1.java (below), and the files jhdf5.jar, jhdf5.dll, jhdf5obj.jar, and jhdfobj.jar in the same directory. source file Test1.java:
package com.example.test.hdf5; import ncsa.hdf.hdf5lib.H5; import ncsa.hdf.hdf5lib.HDF5Constants; import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; import ncsa.hdf.object.FileFormat; import ncsa.hdf.object.h5.H5File; public class Test1 < public Test1 () <>public static void main(String args[]) < Test1 test = new Test1(); if (args.length < 2) < >else if ("h5file".equals(args[0])) < test.testH5File(args[1]); >else if ("h5f".equals(args[0])) < test.testH5F(args[1]); >> public void testH5File(String filename) < H5File file; try < file = (H5File) new H5File().createFile( filename, FileFormat.FILE_CREATE_OPEN); file.close(); >catch (Exception e) < throw new RuntimeException(e); >> public void testH5F(String filename) < try < int HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); H5.H5Fclose(id); >catch (HDF5LibraryException e) < throw new RuntimeException(e); >catch (NullPointerException e) < throw new RuntimeException(e); >> >
>> T=javaObject('com.example.test.hdf5.Test1') T = com.example.test.hdf5.Test1@c9a375 >> T.testH5F('c:/tmp/espdf/jj11copy.hdf5') java.lang.UnsatisfiedLinkError: no jhdf5 in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at ncsa.hdf.hdf5lib.H5.(H5.java:276) at ncsa.hdf.hdf5lib.HDF5Constants.(HDF5Constants.java:494) at com.example.test.hdf5.Test1.testH5F(Test1.java:46) Jul 23, 2009 10:38:16 AM ncsa.hdf.hdf5lib.H5 INFO: HDF5 library: jhdf5 resolved to: jhdf5.dll; NOT successfully loaded from java.library.path . Java exception occurred: java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5dont_atexit()I at ncsa.hdf.hdf5lib.H5.H5dont_atexit(Native Method) at ncsa.hdf.hdf5lib.H5.(H5.java:288) at ncsa.hdf.hdf5lib.HDF5Constants.(HDF5Constants.java:494) at com.example.test.hdf5.Test1.testH5F(Test1.java:46) >> T.testH5F('c:/tmp/espdf/jj11copy.hdf5') . Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class ncsa.hdf.hdf5lib.HDF5Constants at com.example.test.hdf5.Test1.testH5F(Test1.java:46) >> T.testH5File('c:/tmp/espdf/jj11copy.hdf5') . Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class ncsa.hdf.hdf5lib.HDF5Constants at ncsa.hdf.object.h5.H5File.(H5File.java:167) at ncsa.hdf.object.h5.H5File.(H5File.java:106) at com.example.test.hdf5.Test1.testH5File(Test1.java:34)
in case it matters, here’s the ant build file I’m using. The JHDF5 .jar files and .dll are in my lib directory; they get copied to the dist directory where my own .jar file is created.
some libraries to use later "/> "/> " destdir="$" debug="on" target="1.6" classpathref="antclasspath" /> "/>
Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
Why do I receive «Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.services.binding.MatlabKeyBindings» when starting MATLAB on Linux or macOS?
Accepted Answer
Direct link to this answer
Direct link to this answer
This error indicates that MATLAB is not able to locate or read your MATLAB preferences directory. This could be due to a setting or variable on your system which is causing MATLAB to look for your preferences in a location where you do not have read access.
Typically this happens due to running a configuration script for MATLAB such as ‘config_matlab.sh’ which attempts to set your preferences directory to a non-default location where you do not have read or write access. You should start by removing the portion of the script which sets your environment variable.
This can also be resolved by creating an environment variable to specify your MATLAB preferences directory immediately before starting MATLAB. You should choose a directory where you have both read and write access. The default location is in your home folder. As an example of the command to run before starting MATLAB, see the following:
This command sets your MATLAB preferences directory to be the default directory inside your home folder. Then, on the next line, the command is to launch MATLAB.
1 Comment
Direct link to this comment
Direct link to this comment
The above bit about environment variables is for OS-X/MacOS and for Linux, and assumes that the user is using a shell derived from ksh . However, ksh and derivatives are case sensitive, and the command in them is export rather than Export . Also the second line needs to begin with /
More Answers (1)
Direct link to this answer
Direct link to this answer
I want to report another common reason matlab on linux would be unable to read the preferences file. I often run matlab over a VPN I establish to the head node of a computer cluster. I then use matlab to submit parallel jobs to the compute nodes. Sometimes, I’ll have more than one VPN tunnel established at once- one from a work computer, then later another from my laptop, or maybe from a different work computer. None of my tunnels can see the other’s applications, so I end up running multiple copies of matlab operating out of my same user folder.
If one matlab opens the preference file for writing, perhaps because I made a change to the window arrangement, then when I attempt to open the second matlab through a different terminal, I receive this error.
If this applies to anyone else, the solution is that if you change the preferences in one instance of matlab, reboot this one before trying to open other instances. If you already have multiple instances running when you change the preferences from one instance, the others will stay open, but will throw this error when you try to reboot them.
Why do I receive an error when starting MATLAB which states: Fatal Error on startup: Java exception occurred: java.lang.NoClassDefFoundError;Could not initalize class sun awt Win32FountManager
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français