我有以下代码:JPanel panel = new JPanel(new MigLayout());;JLabel label = new JLabel("Sample Label")panel.add(label, "gaptop 20, gapbottom 20,wrap");当我查看MigLayout文档时,上面的代码对我来说看起来是有效的,但在运行时它会抛出java.lang.ClassCastException异常,并带有下面的堆栈跟踪java.lang.ClassCastException: java.lang.String cannot be cast to net.miginfocom.layout.CC at com.intellij.ui.layout.migLayout.patched.MigLayout.addLayoutComponent(MigLayout.kt:403) at java.awt.Container.addImpl(Container.java:1128) at java.awt.Container.add(Container.java:973) at com.xxx.size.plugin.MemoryMeasurementTool_Tool.loadToolResultPanel(xxxMeasurementTool_Tool.java:58) at com.xxx.size.plugin.MemoryAnalyzer$1.run(xxxAnalyzer.java:75) at jetbrains.mps.smodel.WorkbenchModelAccess$UndoContextSetup.run(WorkbenchModelAccess.java:378) at jetbrains.mps.smodel.ActionDispatcher.dispatch(ActionDispatcher.java:84) at jetbrains.mps.smodel.ActionDispatcher.lambda$wrap$0(ActionDispatcher.java:105) at jetbrains.mps.smodel.ActionDispatcher.dispatch(ActionDispatcher.java:84) at jetbrains.mps.smodel.ActionDispatcher.lambda$wrap$0(ActionDispatcher.java:105) at jetbrains.mps.smodel.LockRunnable.run(LockRunnable.java:60) at jetbrains.mps.smodel.TryRunPlatformWriteHelper.lambda$tryWrite$2(TryRunPlatformWriteHelper.java:122) at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1057) at jetbrains.mps.smodel.TryRunPlatformWriteHelper.runWrite(TryRunPlatformWriteHelper.java:103) at jetbrains.mps.smodel.TryRunPlatformWriteHelper.tryWrite(TryRunPlatformWriteHelper.java:120) at jetbrains.mps.smodel.WorkbenchModelAccess.lambda$tryWriteInCommand$4(WorkbenchModelAccess.java:226) at jetbrains.mps.util.ComputeRunnable.compute(ComputeRunnable.java:32) at jetbrains.mps.util.AbstractComputeRunnable.run(AbstractComputeRunnable.java:27)
1 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
看起来,您使用了错误的导入(您使用由 Intellij Idea 修补的 MigLayout,该用法可能与标准用法不同)。检查您的 MigLayout 是否导入为:
import net.miginfocom.swing.MigLayout;
添加回答
举报
0/150
提交
取消