Search code examples
javakarel

Stanford's Karel the Robot throws NullPointerException


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


Solution

  • You are getting that error because you are not using the Eclipse version provided by the Stanford University. For more detailed information,

    Edit: Deleted this link as it is not working anymore.

    Edit:

    Since the above link is not working anymore, I wrote the following steps. Since I am not using Karel anymore, if someone followed through the guide and can make any corrections, please comment of edit this answer.

    Instructions:

    a.Visit Stanford website and download the following softwares

    1. Eclipse for windows from Stanford
    2. Java Jre software

    b.Install the softwares.

    c.Download Assignment1.zip from Assignments tab.

    d.Install the Assignment into Eclipse.

    Now, we are done with the setup guide. Lets discuss about the common problems:

    Problems:

    Problem 1 : Blank Screen

    This means, you installed the latest version of the Sun Java JRE software. The solution to this problem is I. Uninstall all the JRE software versions except the one downloaded from the Stanford Website.

    OR, try this

    a.Open Eclipse Software.

    b.In the Menu toolbar, Click Window and then Click Preferences

    c. Follow these simple steps:

    1. In the Preferences window, Click Java.
    2. In the drop down section shown under Java, click Installed JREs.
    3. The JRE we downloaded from the Stanford website is the jre6 update 2. So select it. Only jre6 is compatible with the stanford eclipse software. So, uncheck all the other versions installed in your system and check the jre6 box as shown in the image below.
    4. Click Ok. 5.Run the program. Now you can see that the output is fine.

    Problem 2 : Error

    When you run the program, you may sometimes notice this error.

    *

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

    *

    This means you did not download the Stanford Eclipse Software and you are using the latest version of the Eclipse that you have downloaded from the Eclipse website. So follow the detailed guide that I mentioned above. Everything will work fine.