MATLAB Help Center
Error message based on Java feature support
MSG = javachk(feature)
javachk(feature,component)
MSG = javachk(feature) returns a generic error message if the specified Java® feature is not available in the current MATLAB® session.
MSG
feature
example
javachk(feature,component) also names the specified component in the error message.
component
collapse all
To test if Java is available before calling a Java command, use these statements. The isempty function is true when there is no error.
isempty
if isempty(javachk('jvm')) scalar = java.lang.Double(5); end
To provide context in the javachk error message, add the optional text parameter to the javachk function.
javachk
Create a script, myFile.m, with the following statements. The script checks if Java is available before calling Java to create a frame.
myFile.m
error(javachk('awt','myFile')) myFrame = java.awt.Frame; myFrame.setVisible(1)
Start MATLAB from the Linux® system prompt.
matlab -nojvm
Run the script.
myFile
If Java is not available, then MATLAB displays this error, identifying the source as the myFile script.
Error using myFile (line 1) myFile is not supported because: Java is not currently available.
'awt'
'desktop'
'jvm'
'swing'
Java feature, specified as one of these values.
UI components in the Java Abstract Window Toolkit (AWT) are available.
MATLAB interactive desktop is running. For more information, see desktop option will not be supported.
Java Virtual Machine software (JVM®) is available.
Swing components (Java lightweight UI components in the Java Foundation Classes) are available.
Identifier, specified as a string or a character vector, to display in the error message.
Data Types: string | char
string
char
Error message, returned as a structure with the following fields. If the feature is available, javachk returns an error structure with empty fields.
message
Message, specified as a character vector.
identifier
Identifier, specified as a character vector.
expand all
desktop
The desktop option for the feature argument will be removed in a future release.
usejava | error
usejava
error
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
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.
Americas
Europe
Asia Pacific
Contact your local office