fixes 'Selection does not contain a main type' error.
Install the AspectJ Development Tools, select new.../other... then open the AspectJ folder, open the AspectJ examples folder, install an example (I used the Tracing example).
Next, use the new... wizard to create an aspect (.aj) file in the top level source folder (tracing in my case). Then copy the aspectJ code from one of the sub folders (in my case, I copied the code in tracing/version1/TraceMyClasses.aj) into your new aspect file. Then, expand the .aj file in the explorer, right click on the *main* method, select run as *java* application. Obvious isn't it?
If I follow your steps exactly, then the result is a compile error.
Ie- you don't mention changing package names, and you don't mention copying over Trace.java.
After I do that and make the project compile cleanly, I can right-click and run the main method from within the aspect as expected.
Make sure that the project compiles cleanly and then try again. Also, make sure that you have JDT Weaving enabled.
If you do both of those and still have a problem, please raise bug on bugzilla and attach the project (or if you can, attach the project to this mailing list thread).
Thanks for the additional info (after all the trouble I had getting this to work, I just assumed anyone able to get that far would know to fixup the package names and copy the helper classes). But you also mention having JDT weaving enabled. How do I do that????
If I follow your steps exactly, then the result is a compile error.
Ie- you don't mention changing package names, and you don't mention copying over Trace.java.
After I do that and make the project compile cleanly, I can right-click and run the main method from within the aspect as expected.
Make sure that the project compiles cleanly and then try again. Also, make sure that you have JDT Weaving enabled.
If you do both of those and still have a problem, please raise bug on bugzilla and attach the project (or if you can, attach the project to this mailing list thread).
Thanks for the additional info (after all the trouble I had getting this to work, I just assumed anyone able to get that far would know to fixup the package names and copy the helper classes). But you also mention having JDT weaving enabled. How do I do that????
I have a similar problem. Six months ago, using Eclipse Helios, I created an Aspect J project and used it to weave around a Java project. Haven't used the AspectJ at all since then. I had need of it, so I resurrected it again. In the meantime I had upgraded to Eclipse Indigo and had not added the AspectJ Plugin. After adding it and trying to launch the Aspect J program wrapping my Java program, I get the 'Selection does not contain a main type' error, even though I can clearly see the main method and even though JDT weaving is already enabled. Any ideas? This all worked before the Eclipse upgrade.
I am having the same problem after upgrading a bunch of stuff. I found this thread through a google search of the error.
Here is the stack trace:
org.eclipse.core.runtime.CoreException: The file does not exist.
at org.eclipse.core.internal.filebuffers.ResourceFileBuffer.create(ResourceFileBuffer.java:237)
at org.eclipse.core.internal.filebuffers.TextFileBufferManager.connect(TextFileBufferManager.java:112)
at org.eclipse.ui.editors.text.TextFileDocumentProvider.createFileInfo(TextFileDocumentProvider.java:559)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.createFileInfo(CompilationUnitDocumentProvider.java:969)
at org.eclipse.ui.editors.text.TextFileDocumentProvider.connect(TextFileDocumentProvider.java:478)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.connect(CompilationUnitDocumentProvider.java:1229)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:4056)
at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:217)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetInput(AbstractDecoratedTextEditor.java:1444)
at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.internalDoSetInput(JavaEditor.java:2578)
at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:2551)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:1371)
at org.eclipse.ui.texteditor.AbstractTextEditor$19.run(AbstractTextEditor.java:3043)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:759)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:756)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2606)
at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3061)
at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3088)
at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:798)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:647)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1254)
at org.eclipse.ui.internal.PartStack.handleDeferredEvents(PartStack.java:1222)
at org.eclipse.ui.internal.LayoutPart.deferUpdates(LayoutPart.java:400)
at org.eclipse.ui.internal.PartSashContainer.handleDeferredEvents(PartSashContainer.java:1409)
at org.eclipse.ui.internal.LayoutPart.deferUpdates(LayoutPart.java:400)
at org.eclipse.ui.internal.WorkbenchPage.handleDeferredEvents(WorkbenchPage.java:1420)
at org.eclipse.ui.internal.WorkbenchPage.deferUpdates(WorkbenchPage.java:1410)
at org.eclipse.ui.internal.WorkbenchPage.closeEditors(WorkbenchPage.java:1384)
at org.eclipse.ui.internal.WorkbenchPage.closeEditor(WorkbenchPage.java:1439)
at org.eclipse.ui.internal.EditorPane.doHide(EditorPane.java:61)
at org.eclipse.ui.internal.PartStack.close(PartStack.java:541)
at org.eclipse.ui.internal.EditorStack.close(EditorStack.java:206)
at org.eclipse.ui.internal.PartStack$1.close(PartStack.java:120)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:83)
at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:269)
at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:278)
at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)
at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$1.closeButtonPressed(DefaultTabFolder.java:71)
at org.eclipse.ui.internal.presentations.PaneFolder.notifyCloseListeners(PaneFolder.java:631)
at org.eclipse.ui.internal.presentations.PaneFolder$3.close(PaneFolder.java:206)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1595)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:261)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
I have Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110301-1815
I've done everything I can think of, deleting the project, going to an older version of my project, etc. nothing seems to work. Cleaning, etc. etc.
When I look at main.xml, displaying the graphical plainly doesn't work. And in my main acitvity for the code:
setContentView(R.layout.main);
I get the error: main cannot be resolved or is not a field
I don't think I do actually. I was simply trying to do a build of the project. It was conking out immediately trying to resolve some of the R ids. It had taken place after I did a bunch of updates on everything.
I did find the solution to my problem however. Actually changing an import from
import android.R;
to
import you.package.R;
did the trick.
Maybe you could tell me what changed out of curiosity.