?
Solved

java.lang.InstantiationException

Posted on 2007-10-02
5
Medium Priority
?
976 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
0
Comment
Question by:slider161
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 20003727
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.
0
 

Author Comment

by:slider161
ID: 20006614
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?
0
 

Author Comment

by:slider161
ID: 20035664
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

 
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20438976
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question