This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Error message based on Java feature support


MSG = javachk(feature)



MSG = javachk(feature) returns a generic error message if the specified Java® feature is not available in the current MATLAB® session.


javachk(feature,component) also names the specified component in the error message.


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.

if isempty(javachk('jvm'))
   scalar = java.lang.Double(5);

To provide context in the javachk error message, add the optional text parameter to the javachk function.

Create a script, myFile.m, with the following statements. The script checks if Java is available before calling Java to create a frame.

myFrame = java.awt.Frame;

Start MATLAB from the Linux® system prompt.

matlab -nojvm

Run the script.


If Java is not available, 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.

Input Arguments

collapse all

Java feature, specified as one of these values.


UI components in the Java Abstract Window Toolkit (AWT) are available.


MATLAB interactive desktop is running.


Java Virtual Machine software (JVM™) is running.


Swing components (Java lightweight UI components in the Java Foundation Classes) are available.

Identifier, specified as a character vector, to display in the error message.

Data Types: char

Output Arguments

collapse all

Error message, returned as a structure with the following fields. If the feature is available, javachk returns an error structure with empty fields.

Message, specified as a character vector.

Identifier, specified as a character vector.

See Also


Introduced before R2006a

Was this topic helpful?