need some eclipse/java help

Soldato
Joined
1 Jun 2005
Posts
5,152
Location
Kent
I've started to try and learn basic programming and some java by going through stanfords programming methodologies lectures on youtube http://www.youtube.com/playlist?list=PL84A56BC7F4A1F852 and trying to work through their course materials http://www.stanford.edu/class/cs106a/index.html

Now one of the first things they teach is a little program that allows you to program it to move around, pick up and drop stuff etc..., and they want you to use simple methods that it's already programmed for to create patterns and solve simple problems.

What I've done is downloaded the eclipse from their link, set it up to use Java 6 (as some people say it has issues with the latest version), and then downloaded their assignments and am currently trying to get the program that goes with lecture 2 to work, a basic karel program.

I downloaded the zip, extracted it to a folder and it contains some .java files, some .class files, and a karel.jar. I loaded the .java file into eclipse:

Code:
/*
 * File: FirstKarelProgram.java
 * ----------------------------
 * This program solves the problem of moving a beeper to a ledge.
 */

import stanford.karel.*;

public class FirstKarelProgram extends Karel {
	public void run() {
		move();
		pickBeeper();
		move();
		turnLeft();
		move();
		turnRight();
		move();
		putBeeper();
		move();
	}
	
	private void turnRight() {
		turnLeft();
		turnLeft();
		turnLeft();
	}

}

The problem is, every time I try to click run I get an error "workspace does not contain a main type (do you have a public void run() method?)

Obviously there is a public void run() method, and the examples in the lecture just run fine. So I would be grateful if anyone can help solve this problem.


It's a little hard to solve these issues when I'm just watching youtube videos rather than sitting in a classroom, but these youtube videos are far more interesting and getting me more excited about programming than just reading a book or following a guide online. So if I can just get this working I think I will be with a good shot of really getting into this.
 
Last edited:
from what I understand, the karel.jar file is the main program itself containing the main code for the program and the lectures/assignements all just create additional methods that 'extend' that original karel program that we shouldn't need to touch.

Since this 'firstKarelProgram.java' file is designed to extend karel (which I assume means karel.jar as that contains all the working operations and such) shouldn't eclipse just load the original karel with the methods in this .java extended on? thats how it all seems to work in the youtube lectures, he just has these .java files up and just runs them and it loads the karel program.

Edit: well I've now got a step closer, I found out how to correctly import all the files together into a single project, and it doesn't give an error about no main type any more. but now when I try to run the firekarelprorgam.java from the project the debug window gives an error on the thread about a unsupported class version error, and the main window gets a new tab saying source not found.

Bah, so many little issues. Stanford really haven't done much to support those trying to learn this way :(
 
Last edited:
OK, I've got the project correctly imported, I opened the firstkarelprogram.java from the package explorer window (this is should work without me needing to do anything). and this is the error that comes up when running:

Code:
FirstKarelProgram (1) [Java Application]	
	FirstKarelProgram at localhost:56640	
		Thread [main] (Suspended (exception UnsupportedClassVersionError))	
			Launcher$AppClassLoader(ClassLoader).defineTransformedClass(String, byte[], int, int, ProtectionDomain, ClassFormatError, String, boolean) line: not available	
			Launcher$AppClassLoader(ClassLoader).defineClassCond(String, byte[], int, int, ProtectionDomain, boolean) line: not available	
			Launcher$AppClassLoader(ClassLoader).defineClass(String, byte[], int, int, ProtectionDomain) line: not available	
			Launcher$AppClassLoader(SecureClassLoader).defineClass(String, byte[], int, int, CodeSource) line: not available	
			Launcher$AppClassLoader(URLClassLoader).defineClass(String, Resource, boolean) line: not available	
			URLClassLoader.access$000(URLClassLoader, String, Resource, boolean) line: not available	
			URLClassLoader$1.run() line: not available	
			AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]	
			Launcher$AppClassLoader(URLClassLoader).findClass(String) line: not available	
			Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available	
			Launcher$AppClassLoader.loadClass(String, boolean) line: not available	
			Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available	
	C:\Program Files (x86)\Java\jre6\bin\javaw.exe (31 May 2012 14:59:57)

And along with that is a new tab saying source not found and a button to edit soruce lookup path, but I don't know what I need to do.
 
looks like it's having problems running it with java 6. You can specify it to run in an older version by configuring your run time parameters, I believe it's something like -version:1.4 (for running in Java 4 mode)

Thanks for that, I had a look at the specific file that stanford links to along side it's link to eclipse and it uses 1.6, (which I confused with the java 6 thing I have), so I downloaded 1.6, set up eclipse to use that and it seems to work now, at least for the pre-made extension for karel :) Now I'll have to try make my own code for it and see if everything is till good.

Thanks for the help.
 
Back
Top Bottom