eclipse:'未能创建部件的控件'错误,StringIndexOutOfBoundsException

时间:2016-02-29 19:07:08

标签: java eclipse

我正在尝试在eclipse中加载文件,我收到以下错误:

enter image description here

我之前加载过此文件没有问题。我在不同的项目中也有这个文件的多个版本控制版本,并且它们都会得到相同的错误。我没有遇到任何导致错误的其他文件。我可以在任何其他文本编辑器中加载该文件。

我以前从未见过这个。我用Google搜索了这个问题,我看到了一堆关于完全不相关的问题的讨论,这让我相信这只是一个通用错误,我不知道如何调试它。这是完整的堆栈跟踪:

java.lang.StringIndexOutOfBoundsException: String index out of range: 63
    at java.lang.String.charAt(Unknown Source)
    at com.cb.eclipse.folding.java.calculation.UserDefinedRegionHelper.isSentinel(UserDefinedRegionHelper.java:53)
    at com.cb.eclipse.folding.java.calculation.UserDefinedRegionHelper.isOpeningSentinel(UserDefinedRegionHelper.java:29)
    at com.cb.eclipse.folding.java.calculation.CommentHelper.isUserDefinedSentinel(CommentHelper.java:90)
    at com.cb.eclipse.folding.java.calculation.CommentHelper.handle(CommentHelper.java:67)
    at com.cb.eclipse.folding.java.calculation.AbstractBlockStrategy.handle(AbstractBlockStrategy.java:93)
    at com.cb.eclipse.folding.java.calculation.CompositeCalculationStrategy.handle(CompositeCalculationStrategy.java:24)
    at com.cb.eclipse.folding.java.calculation.CommentPrefixStrategy.handle(CommentPrefixStrategy.java:64)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.computeProjections(JavaProjectionCalculator.java:230)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:96)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:108)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:108)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:68)
    at com.cb.eclipse.folding.java.calculation.ProjectionChangeReconciler.reconstructAnnotations(ProjectionChangeReconciler.java:173)
    at com.cb.eclipse.folding.java.calculation.ProjectionChangeReconciler.initialize(ProjectionChangeReconciler.java:99)
    at com.cb.eclipse.folding.java.EnhancedJavaFoldingStructureProvider.initialize(EnhancedJavaFoldingStructureProvider.java:115)
    at com.cb.eclipse.folding.java.EnhancedJavaFoldingStructureProvider$ProjectionListener.projectionEnabled(EnhancedJavaFoldingStructureProvider.java:201)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.fireProjectionEnabled(ProjectionViewer.java:488)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.enableProjection(ProjectionViewer.java:536)
    at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.setVisibleDocument(JavaSourceViewer.java:681)
    at org.eclipse.jface.text.TextViewer.setDocument(TextViewer.java:2934)
    at org.eclipse.jface.text.source.SourceViewer.setDocument(SourceViewer.java:643)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.setDocument(ProjectionViewer.java:375)
    at org.eclipse.jface.text.source.SourceViewer.setDocument(SourceViewer.java:591)
    at org.eclipse.ui.texteditor.AbstractTextEditor.initializeSourceViewer(AbstractTextEditor.java:4050)
    at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3578)
    at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:54)
    at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:447)
    at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createPartControl(JavaEditor.java:3125)
    at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.createPartControl(CompilationUnitEditor.java:1502)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:341)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:898)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:879)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:121)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:345)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:264)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
    at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:971)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:640)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:746)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:717)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:711)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:695)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:99)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
    at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
    at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
    at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:85)
    at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:59)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
    at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:494)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:458)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:724)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:396)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1166)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3234)
    at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3149)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3131)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3126)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3090)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3080)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:373)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:179)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:268)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:233)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:275)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(PackageExplorerActionGroup.java:376)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$4.open(PackageExplorerPart.java:538)
    at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
    at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:854)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
    at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:851)
    at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1168)
    at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1275)
    at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:278)
    at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:272)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:313)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)

3 个答案:

答案 0 :(得分:5)

UserDefinedRegionHelper.isSentinel的代码在那里:https://github.com/al3xandru/coffee-bytes/blob/master/com.cb.eclipse.folding/src/com/cb/eclipse/folding/java/calculation/UserDefinedRegionHelper.java

更特别的是:

ISourceReference reference = (ISourceReference) owner;

        String contents = reference.getSource();
        ISourceRange range = (ISourceRange)reference.getSourceRange();


        int correctedStart = start - range.getOffset();
        // Math.min should be redundant (no JavaElement should contain half of a comment)
        int correctedEnd = Math.min( (end - range.getOffset()) , range.getLength());

        //System.out.println("Checking for sentinel: " + contents.substring(correctedStart, correctedEnd));
        boolean keepScanning = true;
        int shift = correctedStart+2; // +2 refers to the // characters which we know we can remove

        while(keepScanning && shift <= correctedEnd) {
            char nextChar = contents.charAt(shift);

            if(nextChar != ' ' && nextChar != '\t') {
                keepScanning = false;               
            }
            else {
                shift++;
            }

        }

异常发生在

char nextChar = contents.charAt(shift);

此代码解析注释行。所以我的猜测是,在这个特定的文件中,你最后写了一个带有特殊字符的评论......但是没有你的源代码就很难说出来了!

答案 1 :(得分:0)

按照上面的说法,我尝试删除代码中的所有注释,但这不是我的问题。我实际上发现问题是

  private static final NavigableMap<Long, String> suffixes = new TreeMap<>();
static {
        suffixes.put(1_000L, "k");
        suffixes.put(1_000_000L, "M");
        suffixes.put(1_000_000_000L, "B");
        suffixes.put(1_000_000_000_000L, "T");
        suffixes.put(1_000_000_000_000_000L, "P");
        suffixes.put(1_000_000_000_000_000_000L, "E");
       }

哪个实际编译并且工作得很好但不确定为什么。 = /

希望有所帮助

答案 2 :(得分:0)

我参加聚会有点晚了,但是对于现在有这个问题的人(包括我),这是解决方法

在堆栈跟踪中,它提到:

...
 at com.cb.eclipse.folding.java.*
...

表示这是代码折叠的问题。

您可以通过以下方法进行验证:关闭文件,打开另一个(有效的)java文件,禁用代码折叠,然后重新打开原始文件。它应该没有问题地打开。

该问题是由一行末尾的注释不完整引起的。例如。

private boolean example = false; //

删除//,或在解决问题后添加单个字符。