Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stanford's Karel the Robot throws NullPointerException

Tags:

java

karel

I have started taking the course Programming methodology(CS106A) available at stanford website. But I am not able to start the Stanford Karel in it.

I am using eclipse indigo classic 3.7.1 and Windows 7 64 bit OS..

I wrote the following code:

import stanford.karel.*;

public class CollectNewspaperKarel extends SuperKarel {
    // You fill in this part
    public void run(){
      move();
      move();
    }
}

It gives the error

Exception in thread "main" java.lang.NullPointerException
   at acm.program.Program.main(Program.java:917)
   at stanford.karel.Karel.main(Karel.java:202)

I followed some instructions given here but then got a blank screen as the output.

The assignment1 of stanford can be found here, and karel the robot of stanford is available here

like image 609
bhuwansahni Avatar asked Jan 07 '12 12:01

bhuwansahni


2 Answers

hello bhuwansahni though I have written an answer before, but now I am writing the entire process to run Karel in any eclipse version.

  1. Create a new project in your Eclipse (File-----> New-----> Java Project)

  2. Load your assignment in the Created Project.

    step a:- Extract Assignment 1 in your desired folder.

    step b:- import the assignment (File-----> Import----->General-----> Files system-----> browse your folder and complete the importing.)

  3. Now run it in a different way (Run-----> Run Configurations-----> )

    Step a:- Under Java Applet Create New Configuration.

    Step b:- Under Main write the Main Class stanford.karel.Karel

    Picture for **Step b of Step 3] http://i.stack.imgur.com/0LpI3.jpg

    Step c:- Under (x)= Arguments in Program Arguments write code=CollectNewspaperKarel

    Picture for **Step b of Step 3] http://i.stack.imgur.com/alIss.jpg

    Step d:- Apply and Run

  4. Now Here comes the Karel the most Lovable Robot.

    Picture for **Step 3] URL:- (i.stack.imgur.com/d8SAa.jpg) put http:// in front to see it... as here I can't post more than two hyperlinks.

like image 82
Indranil Sinha Avatar answered Oct 17 '22 15:10

Indranil Sinha


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 need Java6.

In Eclipse:

  1. Project >> Settings >> Java Compiler: Select 1.6
  2. Right click Run button >> Run Configuration >> JRE Tab >> Alertnative JRE: Select/add your Java 6 path

Then I implement a main method for each project like the one above. For each rename StoneMasonKarel.class to whatever your class name is.

like image 22
user2643648 Avatar answered Oct 17 '22 15:10

user2643648