This kind of error is generally due to the incompatibility of some environment configurations of java.
Execute the following command, some default values will appear,
echo $JAVA_HOME
echo $CLASSPATH
At this time, enter the following command in the current terminal (only valid for the current terminal, so it will not affect the operation of other programs in your system):
export JAVA_HOME=
export CLASSPATH=