stanford Java公开课Karel机器人开发环境eclipse安装与配置
1:安装jdk1.8,是否成功打开cmd,java-version
有些教程说需要配置环境变量,
PATH,JAVA_HOME,CLASS_PATH等,我第一次配置了,cmd里使用java命令正常。后来没有配置,也可以正常使用。
如果cmd里面没有java命令,需要配置下,这里不做描述。
2:安装stanford下载的eclipse,解压后直接运行,不需要安装,eclipse官网下载的,需要加入一个组件edu.stanford.cs106_2.0.1.201603271702.jar
3:安装jdk6。为什么安装jdk1.6,因为Karel机器人的程序在jdl1.8里,无法运行。我测试过会出错误。
为什么先安装jdk1.8,再安装jdk1.6?
因为我第一次操作,先安装1.6,再打开eclipse,无法运行,提示需要jdk1.8的支持。
所以我先安装1.8,运行eclipse成功。再次安装1.6,在eclipse里切换当前使用的jdk版本,切换到1.6。正常运行Karel机器人程序。
4:导入BlankKarel,
/* * File: BlankKarel.java * --------------------- * This is a blank Karel project that you can change at will. Remember, if you change * the class name, you'll need to change the filename so that it matches. * If you want to make the program load with a specific world, make the * world file named the same as this class. For example, when this program is * run, it would try to load BlankKarel.w if there is one. */
//import acm.program.*; import stanford.karel.*;
public class StoneMasonKarel extends SuperKarel { public static void main(String[] args){ stanford.karel.Karel.main(new String[]{ "code=" +StoneMasonKarel.class.getCanonicalName() });
} public void run() { /* You fill this in */ move(); move(); } }
|
运行时候出错误,使用jdk8会出错的,需要使用jdk6。
错误报警为
Exception in thread "main" java.lang.NullPointerException at acm.program.Program.main(Program.java:917) at stanford.karel.Karel.main(Karel.java:202) |
下面是在eclipse里设置使用jdk1.6的操作
RUN Configurations
下面是运行结果
官方教程The art and science of java
里第一个GUI程序。
import acm.graphics.*;
import acm.program.*;
public class hello extends GraphicsProgram {
public void run(){
add(new GLabel("hello world stanford"),100,75);
}
}
也可以正常运行。
虽然很喜欢CSDN,但是这里的博客编辑器真的不好用。
插入图片,无论光标在哪里,图片都跑到第一行,插入代码段也是。