Link to home
Start Free TrialLog in
Avatar of slider161
slider161

asked on

java.lang.InstantiationException

am writing an Ant script to run a JUnit test suite within an Eclipse plug-in and generate a JUnit report outside of Eclipse. I am referring to this tutorial

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.test/testframework.html?revision=1.4

I have written a test.xml file for my plug-in which uses the org.eclipse.test library.xml file run the suite and generate a report.

When I run the script I get the following error:

"org.osgi.framework.BundleException: The activator org.eclipse.core.runtime.Plugin for bundle com.propylon.core.Test is invalid "

"Caused by: java.lang.InstantiationException"

however the the class in-question is not an interface or abstract

Below is the class:

package com.propylon.core.tests;

import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends Plugin {

      // The plug-in ID
      public static final String PLUGIN_ID = "com.propylon.core.tests";

      // The shared instance
      private static Activator plugin;
      
      /**
       * The constructor
       */
      public Activator() {
      }

      /*
       * (non-Javadoc)
       * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
       */
      public void start(BundleContext context) throws Exception {
            super.start(context);
            plugin = this;
      }

      /*
       * (non-Javadoc)
       * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
       */
      public void stop(BundleContext context) throws Exception {
            plugin = null;
            super.stop(context);
      }

      /**
       * Returns the shared instance
       *
       * @return the shared instance
       */
      public static Activator getDefault() {
            return plugin;
      }

}

below is the stacktrace:

java-test:
        [echo] Running com.propylon.core.tests.testcase.AllTests. Result file: C:/eclipse3.3/results/com.propylon.core.tests.testcase.AllTests.xml.
        [java] org.osgi.framework.BundleException: The activator org.eclipse.core.runtime.Plugin for bundle com.propylon.core.Test is invalid
        [java]       at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:141)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:970)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
        [java]       at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)
        [java]       at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
        [java]       at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:111)
        [java]       at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:417)
        [java]       at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:189)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:340)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:408)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:369)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:357)
        [java]       at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
        [java]       at java.lang.ClassLoader.loadClass(Unknown Source)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:289)
        [java]       at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
        [java]       at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1269)
        [java]       at org.eclipse.test.EclipseTestRunner.loadSuiteClass(EclipseTestRunner.java:302)
        [java]       at org.eclipse.test.EclipseTestRunner.getTest(EclipseTestRunner.java:233)
        [java]       at org.eclipse.test.EclipseTestRunner.<init>(EclipseTestRunner.java:216)
        [java]       at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:200)
        [java]       at org.eclipse.test.CoreTestApplication.runTests(CoreTestApplication.java:35)
        [java]       at org.eclipse.test.CoreTestApplication.run(CoreTestApplication.java:31)
        [java]       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]       at java.lang.reflect.Method.invoke(Unknown Source)
        [java]       at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethod(EclipseAppContainer.java:533)
        [java]       at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:155)
        [java]       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
        [java]       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
        [java]       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
        [java]       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
        [java]       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]       at java.lang.reflect.Method.invoke(Unknown Source)
        [java]       at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
        [java]       at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
        [java]       at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
        [java]       at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
        [java]       at org.eclipse.core.launcher.Main.main(Main.java:30)
        [java] Caused by: java.lang.InstantiationException
        [java]       at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
        [java]       at java.lang.reflect.Constructor.newInstance(Unknown Source)
        [java]       at java.lang.Class.newInstance0(Unknown Source)
        [java]       at java.lang.Class.newInstance(Unknown Source)
        [java]       at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:136)
        [java]       ... 41 more
        [java] Java Result: 2

How am I getting this error?

thank you for your time

Slider
Avatar of Ajay-Singh
Ajay-Singh

I don't understand why you are writing plugin for this. When I look the
link, it suggests not to - the existing plugin should work as-is.
Avatar of slider161

ASKER

I am not implementing the tutorial, instead I am applying it to my own problem. I have written a test.xml  to run my plugin. The test.xml uses the library.xml in the org.eclipse.test plugin to run the tests and generate a report.

 My JUnit tests must be inside a plugin, where does it say not have unit tests in a plugin?
I trying to activate a plugin that runs a JUnit test suite using an Ant script. However I keep getting an error

 

"The activator org.eclipse.core.runtime.Plugin for bundle com.propylon.core.Test is invalid"

 

"Caused by: java.lang.InstantiationException"

 

Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class.

 

Somewhere the Class.newInstance() method is being invoked on Plugin (the abstract class) rather than Activator (the non-abstract one), why?

 

I created the plugin project using the eclispe wizard this its the Activator class it generated

 

package com.propylon.core.test;

 

import org.eclipse.core.runtime.Plugin;

import org.osgi.framework.BundleContext;

 

/**

* The activator class controls the plug-in life cycle

*/

public class Activator extends Plugin {

 

// The plug-in ID

public static final String PLUGIN_ID = "com.propylon.core.Test";

 

// The shared instance

private static Activator plugin;

 

/**

* The constructor

*/

public Activator() {

}

 

/*

* (non-Javadoc)

* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)

*/

public void start(BundleContext context) throws Exception {

super.start(context);

plugin = this;

}

 

/*

* (non-Javadoc)

* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)

*/

public void stop(BundleContext context) throws Exception {

plugin = null;

super.stop(context);

}

 

/**

* Returns the shared instance

*

* @return the shared instance

*/

public static Activator getDefault() {

return plugin;

}

 

}



below is the stack trance:

 

java-test:

[echo] Running com.propylon.core.tests.testcase.AllTests. Result file: C:/eclipse3.3/results/com.propylon.core.tests.testcase.AllTests.xml.

[java] org.osgi.framework.BundleException: The activator org.eclipse.core.runtime.Plugin for bundle com.propylon.core.Test is invalid

[java] at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:141)

[java] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:970)

[java] at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)

[java] at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)

[java] at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)

[java] at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:111)

[java] at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:417)

[java] at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:189)

[java] at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:340)

[java] at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:408)

[java] at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:369)

[java] at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:357)

[java] at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)

[java] at java.lang.ClassLoader.loadClass(Unknown Source)

[java] at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:289)

[java] at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)

[java] at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1269)

[java] at org.eclipse.test.EclipseTestRunner.loadSuiteClass(EclipseTestRunner.java:302)

[java] at org.eclipse.test.EclipseTestRunner.getTest(EclipseTestRunner.java:233)

[java] at org.eclipse.test.EclipseTestRunner.<init>(EclipseTestRunner.java:216)

[java] at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:200)

[java] at org.eclipse.test.CoreTestApplication.runTests(CoreTestApplication.java:35)

[java] at org.eclipse.test.CoreTestApplication.run(CoreTestApplication.java:31)

[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

[java] at java.lang.reflect.Method.invoke(Unknown Source)

[java] at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethod(EclipseAppContainer.java:533)

[java] at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:155)

[java] at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)

[java] at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)

[java] at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)

[java] at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)

[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

[java] at java.lang.reflect.Method.invoke(Unknown Source)

[java] at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)

[java] at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)

[java] at org.eclipse.equinox.launcher.Main.run(Main.java:1169)

[java] at org.eclipse.equinox.launcher.Main.main(Main.java:1144)

[java] at org.eclipse.core.launcher.Main.main(Main.java:30)

[java] Caused by: java.lang.InstantiationException

[java] at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)

[java] at java.lang.reflect.Constructor.newInstance(Unknown Source)

[java] at java.lang.Class.newInstance0(Unknown Source)

[java] at java.lang.Class.newInstance(Unknown Source)

[java] at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:136)

[java] ... 41 more

[java] Java Result: 2

 

 Has anyone come across this problem before? Do I need to change some setting in eclipse or modify may activator class?

 

Thank you for your time

 

slider

 
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial