Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JUnit 4 gives NullPointerException

When I try to run a JUnit 4 test i get a NullPointerException in Eclipse. JUnit3 though works.

I'm trying the following test class:

import static org.junit.Assert.fail;
import org.junit.Test;

public class Test {

    @Test
    public void test() {
        fail("Not yet implemented");
    }

}

Here is the Exception Stack Trace:

java.lang.NullPointerException
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.localURL(JUnitLaunchConfigurationDelegate.java:420)
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.entryString(JUnitLaunchConfigurationDelegate.java:409)
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.addEntry(JUnitLaunchConfigurationDelegate.java:396)
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.localizeClasspath(JUnitLaunchConfigurationDelegate.java:387)
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.getClasspath(JUnitLaunchConfigurationDelegate.java:364)
    at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.launch(JUnitLaunchConfigurationDelegate.java:147)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

I'm using OS X Snow Leopard with Java SDK 1.6.0_35 (from Apple). Both JDK and JUnit 4 are in my build path. Has the Java Version something to do with the problem ?

UPDATE:

Ok I'm an idiot not thinking of this. I installed Eclipse for C/C++ Developers as I had to do something in C++. But I also used the same instance to develop for Android with the Android SDK plugin and I did some small Java Applications. But I didn't have the Java Development Tools or the Java EE Developer Tools installed. I installed them now and JUnit 4 works now.

I guess one of this Tools is used for JUnit 4. Strange though that JUnit 3 worked. Anyway it works now.

Thank you all for your support though.

like image 281
mjspier Avatar asked Jan 16 '23 07:01

mjspier


2 Answers

Ok I'm an idiot not thinking of this. I installed Eclipse for C/C++ Developers as I had to do something in C++. But I also used the same instance to develop for Android with the Android SDK plugin and I did some small Java Applications. But I didn't have the Java Development Tools or the Java EE Developer Tools installed. I installed them now and JUnit 4 works now.

like image 114
mjspier Avatar answered Jan 22 '23 21:01

mjspier


I have the same problems, I reinstall the ADT from version to 22.3 to 23 because the upgrade issue. It seems that the new version ADT excludes the 'Java Development Tool'.

You can check the 'Help'->'About'->'Installatoin Details' for details.

So I use the existed Juno upgrade site in eclipse to install the JDT (Juno - http://download.eclipse.org/releases/juno), after that, it works fine.

like image 38
Happier Avatar answered Jan 22 '23 21:01

Happier