javachk
Error message based on Java feature support
Description
Examples
Generate Error If Java Not Available
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); end
Test Java Availability in User-Defined Script
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.
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.
Input Arguments
feature
— Java feature
'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. |
| Java Virtual Machine software (JVM®) is running. |
| Swing components (Java lightweight UI components in the Java Foundation Classes) are available. |
component
— Identifier
string | character vector
Identifier, specified as a string or a character vector, to display in the error message.
Data Types: string
| char
Output Arguments
MSG
— Error message
structure
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
character vector | empty
Message, specified as a character vector.
identifier
— Identifier
character vector | empty
Identifier, specified as a character vector.
Version History
Introduced before R2006a
MATLAB Command
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
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)