We help IT Professionals succeed at work.

java.lang.InstantiationException

1,401 Views
Last Modified: 2013-12-15
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
Comment
Watch Question

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.

Author

Commented:
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?

Author

Commented:
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

 
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.