【发布时间】:2016-01-13 09:44:33
【问题描述】:
我给 int dmcdw 值 'd' 并希望通过异常捕获错误,但它不起作用。
这是我的代码的一部分:
private int dmcdw = d;
private String cdw = "w";
private void cdwPlausi()
{
try
{
if (dmcdw > 0 ^ cdw.substring(0).equalsIgnoreCase("w"))
{
//
}
else
{
//
}
}
catch (NumberFormatException ex)
{
//
}
}
我使用了 NumberFormatException,但它对我不起作用,我做错了什么?
这是显示在我的控制台中的错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
d cannot be resolved to a variable
at importiert.Importiert_Tarif.<init>(Importiert_Tarif.java:19)
at frame.Frame_Main$2.actionPerformed(Frame_Main.java:228)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
【问题讨论】:
-
你说的“它不工作”是什么意思?
-
您能否包含更多代码。你怎么知道它不起作用?
-
@AdamKortylewicz 我不想将 String 'd' 转换为 int,我想获得一个有效的异常处理程序,因此不会发生此类错误
-
就像错误消息所说,
d不是变量。你是说'd'(角色)吗?