У меня есть следующий код класса и при отладки он продолжал показывать следующее сообщение об ошибке:необработанное исключение: Ошибка java.lang.ClassNotFoundException
1.) Необработанное исключение: java.lang.ClassNotFoundException 2.) Необработанное исключение: java.lang.NoSuchMethodException
Журнал ошибок:
/apps/robotapp/Utils.java:32: error: exception IOException is never thrown in body of corresponding try statement
} catch (IOException e) {
^
/apps/robotapp/Utils.java:24: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
final int tckName = Class.forName("libcore.io.OsConstants").getField("_SC_CLK_TCK").getInt(null);
^
/apps/robotapp/Utils.java:24: error: unreported exception NoSuchFieldException; must be caught or declared to be thrown
final int tckName = Class.forName("libcore.io.OsConstants").getField("_SC_CLK_TCK").getInt(null);
^
/apps/robotapp/Utils.java:24: error: unreported exception IllegalAccessException; must be caught or declared to be thrown
final int tckName = Class.forName("libcore.io.OsConstants").getField("_SC_CLK_TCK").getInt(null);
^
/apps/robotapp/Utils.java:25: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
final Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
^
/apps/robotapp/Utils.java:25: error: unreported exception NoSuchFieldException; must be caught or declared to be thrown
final Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
^
/apps/robotapp/Utils.java:25: error: unreported exception IllegalAccessException; must be caught or declared to be thrown
final Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
^
/apps/robotapp/Utils.java:26: error: unreported exception NoSuchMethodException; must be caught or declared to be thrown
final long tck = (Long)os.getClass().getMethod("sysconf", Integer.TYPE).invoke(os, tckName);
^
/apps/robotapp/Utils.java:26: error: unreported exception IllegalAccessException; must be caught or declared to be thrown
final long tck = (Long)os.getClass().getMethod("sysconf", Integer.TYPE).invoke(os, tckName);
^
Note:
/RobotService.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
9 errors
FAILED
фрагмент кода, который имеет ошибки:
try {
final String[] fields = stat.substring(stat.lastIndexOf(field2End)).split(fieldSep);
final long t = Long.parseLong(fields[fieldStartTime]);
final int tckName = Class.forName("libcore.io.OsConstants").getField("_SC_CLK_TCK").getInt(null);
final Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
final long tck = (Long)os.getClass().getMethod("sysconf", Integer.TYPE).invoke(os, tckName);
return t * msInSec/tck;
} catch (final NumberFormatException e) {
throw new IOException(e);
} catch (final IndexOutOfBoundsException e) {
throw new IOException(e);
} catch (IOException e) {
throw new IOException(e);
}
Половина вашего кода кажется отсутствующим (нет видимого блока catch). –
@MattClark Да, я это знаю. Я спрашиваю, как исправить это. – developer