Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » HelloWorldSWT tutorial program does not compile
HelloWorldSWT tutorial program does not compile [message #1830863] Wed, 05 August 2020 11:58 Go to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
Dear forum members,

I have just installed Eclipse again and tried to follow the HelloWorld tutorial. It worked and I think it also did last time.

Then on to the HelloWorldSWT tutorial, which didn't work last time.

I managed I think to import what the tutorial refers to as the 'SWT project' : On the left of the Eclipse window there is now something called 'org.eclipse.swt'.

I was able to follow the remainder of the tutorial without problem and as the tutorial admits, doing so results in several compilation errors. As a consequence, the program can't run.
The program is as follows :

import jdk.nashorn.tools.Shell;
public class HelloWorldSwT {

	public static void main(String[] args) {
		Display display = new Display() ;
		Shell shell = new Shell(display) ;
		Shell.setText("Hello World !") ;
		shell.open() :
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep() ;
		}
		display.dispose() ;
	}
}


Here are the compiler complaints :

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Display cannot be resolved to a type
Display cannot be resolved to a type
The method setText(String) is undefined for the type Shell
The method open() is undefined for the type Shell
Syntax error on token ":", ; expected
The method isDisposed() is undefined for the type Shell

at HelloWorldSwT.main(HelloWorldSwT.java:6)

I suspect that if I continue using Eclipse, I will encounter that type of problem again. Is there somewhere a good guide explaining how to make Eclipse find stuff ?
Re: HelloWorldSWT tutorial program does not compile [message #1830864 is a reply to message #1830863] Wed, 05 August 2020 12:06 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3834
Registered: July 2009
Senior Member

Which HelloWorldSWT tutorial?

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: HelloWorldSWT tutorial program does not compile [message #1830866 is a reply to message #1830864] Wed, 05 August 2020 13:13 Go to previous messageGo to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
Sorry that I forgot to mention that. I am talking about the one that is included in Eclipse, called 'Create a Hello World SwT application'.
Re: HelloWorldSWT tutorial program does not compile [message #1831057 is a reply to message #1830866] Tue, 11 August 2020 00:47 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 211
Registered: July 2009
Senior Member
import jdk.nashorn.tools.Shell; should be import org.eclipse.swt.widgets.Shell;
Re: HelloWorldSWT tutorial program does not compile [message #1831221 is a reply to message #1830863] Fri, 14 August 2020 07:21 Go to previous messageGo to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
Thanks.
I made that modification and also corrected the erroneous line 8. The program is now the following :

import org.eclipse.swt.widgets.Shell ;
public class HelloWorldSwT {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Hello World !") ;
		shell.open() ;
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep() ;
		}
		display.dispose() ;
	}
}


When run, the compiler makes these complaints :

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Display cannot be resolved to a type
Display cannot be resolved to a type
Shell cannot be resolved to a type
Shell cannot be resolved to a type

at HelloWorldSwT.main(HelloWorldSwT.java:7)
Re: HelloWorldSWT tutorial program does not compile [message #1831237 is a reply to message #1831221] Fri, 14 August 2020 16:48 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 211
Registered: July 2009
Senior Member
See https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java. You'll also need to create a dependency on swt.jar such as through placing the jar in a lib folder and adding it to the classpath.

That said, I can't get swt dependency to work on anything later than java 1.8 because it's not modular.
Re: HelloWorldSWT tutorial program does not compile [message #1831304 is a reply to message #1831237] Mon, 17 August 2020 07:14 Go to previous messageGo to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
I have added
package org.eclipse.swt.snippets ;
but don't know how to "create a dependency on swt.jar such as through placing the jar in a lib folder and adding it to the classpath. "

It is still not working and I still don't know how to make Eclipse find the stuff it needs.

I did manage to explain Eclipse how to find org.eclipse.swt.widgets.Shell by adding swt.jar to HelloworldSwT.java's build path.

I did some more meddling and now the program compiles.

import org.eclipse.swt.widgets.* ;

public class HelloWorldSwT {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Hello World !") ;
		shell.open() ;
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep() ;
		}
		display.dispose() ;
	}}


I still don't know how to make Eclipse find stuff in general.

I can understand the developpers don't have time to maintain their tutorials, but I can't understand why they don't just delete the faulty ones.
Re: HelloWorldSWT tutorial program does not compile [message #1831458 is a reply to message #1831304] Thu, 20 August 2020 09:00 Go to previous messageGo to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
I have written another tiny program where I use UCSDUnfoldingMaps.
However, Eclipse is unable to resolved that to a type.

However, I have that package in the package explorer and for classes inside that package Eclipse can find that class, but outside of it not apparently. On the website unfoldingmaps.org/javadoc/ I don't see explained what Eclipse should be looking for.

Again, how can one make Eclipse find the stuff it needs to run a program ?
Re: HelloWorldSWT tutorial program does not compile [message #1831462 is a reply to message #1831458] Thu, 20 August 2020 09:58 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 211
Registered: July 2009
Senior Member
I'm confused. I looked over their website and downloaded the "eclipse" package and imported it into eclipse. All their examples seem to use processing.core.PApplet which uses sun.applet.AppletViewer. This hasn't existed since Java 1.8. Their API (javadocs) however are at the level de.fhpotsdam.unfolding.UnfoldingMap which, takes the PApplet as a constructor argument. What are these people doing? Is the library confined to Java 1.8?
Re: HelloWorldSWT tutorial program does not compile [message #1831478 is a reply to message #1831462] Thu, 20 August 2020 13:08 Go to previous messageGo to next message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
It is a package developped by the University of California San Diego. I am sort of following the course Object Oriented programming in Java on Coursera by their computer science department. UCSDUnfoldingMaps is outdated as it relies on the deprecated Papplet (and perhaps for other reasons as well). I finally managed to make it work by (by among other things) using Java 1.8.
Re: HelloWorldSWT tutorial program does not compile [message #1832316 is a reply to message #1830863] Wed, 16 September 2020 08:17 Go to previous message
Frank Tavernier is currently offline Frank TavernierFriend
Messages: 8
Registered: August 2020
Junior Member
Is there really no one who knows how to make Eclipse find stuff ?

I tried importing stuff in the program at the original location again and that worked. Then copied all the code to the file at the original location. Still no red xes. What has changed ? Now there is a folder UCSDUnfoldingMaps in a folder called 'Referenced Libraries', which I suspect wasn't there before.

index.php/fa/38908/0/

Will it run then ? No. When I tell Eclipse to run that program, it gives the error message box : "src/lifeExpectancyPerCountry [in Trials] does not exist", which is rubbish.

How can one show an image without uploading it to a website first ?
Edit : the preview failed to show the image.

[Updated on: Wed, 16 September 2020 08:18]

Report message to a moderator

Previous Topic:None displaying characters
Next Topic:Unable to update Eclipse Plugin
Goto Forum:
  


Current Time: Mon Sep 21 18:31:12 GMT 2020

Powered by FUDForum. Page generated in 0.02939 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top