Eclipse throws java.lang.NullPointerException on creating android junit test configuration

41.3k views Asked by At

I've got Android project in Eclipse.

I created test project for my Project Try to create test configuration as written at Testing from Eclipse with ADT at developer.android.com.

My actions:

  • Run->Run configurations
  • Select Android JUnit Test->New
  • There is error message "An error has occured. See error log for more details. java.lang.NullPointerException".
  • Log:

    Problems occurred when invoking code from plug-in: "org.eclipse.jface".
    
    java.lang.NullPointerException
    at com.android.ide.eclipse.adt.internal.launch.junit.InstrumentationRunnerValidator.<init>(InstrumentationRunnerValidator.java:48)
    at com.android.ide.eclipse.adt.internal.launch.junit.InstrumentationRunnerValidator.<init>(InstrumentationRunnerValidator.java:59)
    at com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.loadInstrumentations(AndroidJUnitLaunchConfigurationTab.java:954)
    at com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.initializeFrom(AndroidJUnitLaunchConfigurationTab.java:335)
    at org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup.initializeFrom(AbstractLaunchConfigurationTabGroup.java:86)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupWrapper.initializeFrom(LaunchConfigurationTabGroupWrapper.java:194)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.displayInstanceTabs(LaunchConfigurationTabGroupViewer.java:751)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer$8.run(LaunchConfigurationTabGroupViewer.java:623)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.inputChanged(LaunchConfigurationTabGroupViewer.java:640)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.setInput0(LaunchConfigurationTabGroupViewer.java:602)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.setInput(LaunchConfigurationTabGroupViewer.java:578)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.handleLaunchConfigurationSelectionChanged(LaunchConfigurationsDialog.java:941)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog$3.selectionChanged(LaunchConfigurationsDialog.java:560)
    at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:888)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:886)
    at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1726)
    at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:1139)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationView.handleConfigurationAdded(LaunchConfigurationView.java:283)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationView.access$1(LaunchConfigurationView.java:272)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationView$2.run(LaunchConfigurationView.java:261)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog.open(LaunchConfigurationsDialog.java:1132)
    at org.eclipse.debug.ui.DebugUITools$2.run(DebugUITools.java:579)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.debug.ui.DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUITools.java:587)
    at org.eclipse.debug.ui.DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUITools.java:521)
    at org.eclipse.debug.ui.actions.OpenLaunchDialogAction.run(OpenLaunchDialogAction.java:81)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at org.eclipse.ui.internal.views.log.EventDetailsDialog.open(EventDetailsDialog.java:180)
    at org.eclipse.ui.internal.views.log.EventDetailsDialogAction.run(EventDetailsDialogAction.java:98)
    at org.eclipse.ui.internal.views.log.LogView$15.doubleClick(LogView.java:535)
    at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:845)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:843)
    at org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1462)
    at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1246)
    at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:249)
    at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:246)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:307)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
    

I can edit this configuration, but buttons "Apply" and "Run" are disabled and configuration is not added to run button menu.

If try to edit debug configuration, the same problem.

System:

  • Eclipse version: 3.7.1 (the latest)
  • Windows 7 x64
5

There are 5 answers

2
Reactgular On

I figured out a work around that seems to work on my Eclipse installation.

  1. Start Eclipse
  2. List "Run Configurations" from the "Run" menu.
  3. Select the "Android JUnit Test" category, and then click the "New" toolbar icon.
  4. A "New_configuration" will be created, but a "NullPointerException" will be shown. After this it's not possible to edit the configuration.
  5. Exit Eclipse
  6. Open your file explorer, and navigate to [eclipse-workspace].metadata.plugins\org.eclipse.debug.core.launches
  7. This is where the run configurations are stored. Edit the file "New_configuration.launch" with a text editor.
  8. There can't be an empty entry for the PROJEC_ATTR node. For the value attribute type the name of a project that exists in Eclipse.
  9. Save the file.
  10. Rename file to desired run configuration name.
  11. Start Eclipse

You should now be able to edit the JUnit Test configuration for Android without receiving any NullPointer exceptions. I noticed after doing this, there are a few more XML nodes added to the configuration file that were missing before. So it seems that the bug is only during file creation, and not file updating.

I hope this helps other people.

Here is a sample launch file that works (assumes the project name is GemsTest.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <launchConfiguration type="com.android.ide.eclipse.adt.junit.launchConfigurationType">
    <stringAttribute key="com.android.ide.eclipse.adt.commandline" value=""/>
    <intAttribute key="com.android.ide.eclipse.adt.delay" value="0"/>
    <booleanAttribute key="com.android.ide.eclipse.adt.nobootanim" value="false"/>
    <intAttribute key="com.android.ide.eclipse.adt.speed" value="0"/>
    <stringAttribute key="com.android.ide.eclipse.adt.target" value="AUTO"/>
    <booleanAttribute key="com.android.ide.eclipse.adt.wipedata" value="false"/>
    <stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="GemsTest"/>
</launchConfiguration>
0
npakudin On

It seems, I've found the workaround, but it some strange.

  • List item
  • Select ANY project
  • Project -> Properties
  • Java Build Path -> Order and Export
  • Check and uncheck ANY unchecked library
  • Press OK
  • Now can create Android JUnit Test Configuration as usually.
0
Hilary Woodccock-Reynolds On

What we forget sometimes is that Eclipse is written in Java and as a result the problem may be in Eclipse rather than the Android Project we are working on. I had the nullpointerexception and it turned out because I had deleted the AVD which (I am not sure if this is related specifically) was based on a user created device definition. I tried changing the AVD and still got the nullpointerexception. Recreated the initial AVD and the error disappeared.

0
Kamil Grabowski On

I think I have found answer to your problem. Firs it looks like instead of creating test project as a "Android Test Project" you created just simple "Java Project" and you are trying to adopt it to your "Android Project".

Solution:

  1. Delete existing Test Project
  2. Go to File -> New -> Other...
  3. Select "Android Test Project"
  4. Go through wizard

Now if you go to the Run -> Run Configuration... and select Android JUnit Test problem does not occur.

Hope that helped.

0
johsin18 On

Unfortunately, the solution described above does not help in my case.

There is a discussion about the problem here, but there is no other solution suggested than "reinstall everything from scratch".

http://groups.google.com/group/android-developers/browse_thread/thread/13559a5696988c5c

Eclipse 3.7.2, Android Tools 16.0.1