我收到异常java.lang.UnsupportedOperationException:不支持
代码是
private static void mode(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void quality(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void complexity(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void sampleRate(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public static void main(final String[] args)
{
mode(0);
quality(1);
complexity(1);
sampleRate(8000);
JSpeexEnc encoder = new JSpeexEnc();
if (encoder.parseArgs(args, FILE_FORMAT_WAVE)) {
encoder.encode();
}
请告诉我为什么这个例外即将来临......
答案 0 :(得分:1)
您正在调用throws UnsupportedOperationException.
private static void mode(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void quality(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void complexity(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void sampleRate(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
替换为
private static void mode(int i) {
//what you want to do
}
private static void quality(int i) {
//what you want to do
}
private static void complexity(int i) {
//what you want to do
}
private static void sampleRate(int i) {
//what you want to do
}
答案 1 :(得分:1)
该行:
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
是异常的原因。这意味着,无论何时调用此方法,它都会抛出异常,就像您定义它一样!
答案 2 :(得分:0)
您还可以在main方法中处理异常,以避免程序抛出异常。像这样的东西 - :
private static void mode(int i){ 抛出新的UnsupportedOperationException(“尚不支持。”); //要更改生成方法的主体,请选择“工具”|模板。 }
private static void quality(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void complexity(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void sampleRate(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public static void main(final String[] args)
{
try
{
mode(0);
quality(1);
complexity(1);
}catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}