java.lang.NullPointerException at org.eclipse.jface.resource.JFaceResources.getResources - java

I am going to implement wizard with SWT / jface. When I run my program, I have the below error:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:209)
at org.eclipse.jface.resource.JFaceResources.getImageRegistry(JFaceResources.java:402)
at org.eclipse.jface.wizard.Wizard.<init>(Wizard.java:105)
at mypackage.ReservationWizard.<init>(ReservationWizard.java:21)
at mypackage.ReservationWizard.main(ReservationWizard.java:69)
The part of my code:
public class ReservationWizard extends Wizard {
**public ReservationWizard() {**
// setWindowTitle("Hotel room reservation wizard");
// setNeedsProgressMonitor(true);
// setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(null, "Unknown.jpg"));
}
...
public static void main(String[] args) {
**ReservationWizard wizard = new ReservationWizard();**
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
dialog.setBlockOnOpen(true);
dialog.open();
}
}
As seen in the code it has an error, even when the ReservationWizard() is empty. What should I do?
It has an error on the specified lines.
edit:
When I created a display, I have the below error:
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jface.resource.JFaceResources.getFontRegistry(JFaceResources.java:340)
at org.eclipse.jface.window.Window.createShell(Window.java:508)
at org.eclipse.jface.window.Window.create(Window.java:429)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
at org.eclipse.jface.window.Window.open(Window.java:792)
at mypackage.ReservationWizard.main(ReservationWizard.java:76)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.commands.common.EventManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more

You have not created a Display before calling your wizard. The first thing an SWT / JFace application has to do is create the display.
So you need:
public static void main(final String [] args)
{
// Create the display
Display display = new Display();
ReservationWizard wizard = new ReservationWizard();
WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
dialog.setBlockOnOpen(true);
dialog.open();
}

Related

Error: A JNI error has occurred, please check your installation

I am doing following test and got JNI error. This happened with TestNG, I can run this test with with
public void main(String[] args) but not with TestNG.
package restAssurePractice;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
public class ApiBasics {
#Test
public static void restAssuredVerification() {
//baseurl
RestAssured.baseURI="https://reqres.in/";
given().
param("page=2").
when().
get("/api/users").
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
body("data[0].last_name",equalTo("Michael"));
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

Junit is not working in Maven Project

I wrote the following code to read the contents of the arxml file.
#Test
public void second() throws IOException {
private XMLResource resource;
String file = "E:\\Input\\ArText_0001.arxml";
AutosarResourceSetImpl resourceSet = new AutosarResourceSetImpl();
Autosar40ResourceFactoryImpl resourceFactory = new Autosar40ResourceFactoryImpl();
URI uri = URI.createFileURI(file );
Map<?, ?> options = null;
resource = (XMLResource) resourceFactory.createResource(uri);
resource.load(options);
resourceSet.getResources().add(resource);
}
I run the project using clean verify goal , In eclipse its working fine but using maven from command line I am getting the following exception.
java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
Finally i got know I am facing the problem in resource.load(option).Instead of option = null I tried the following way also
option.put(Resource.Factory.Registry.DEFAULT_EXTENSION,new Autosar40ResourceFactoryImpl())
But now also i am getting same exception.Please help me to solve this one?
Exception:
Time elapsed: 12.846 sec <<< ERROR!
java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.EnvironmentalconditionFactory.<clinit>(EnvironmentalconditionFactory.java:41)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.impl.EnvironmentalconditionPackageImpl.<init>(EnvironmentalconditionPackageImpl.java:1152)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.impl.EnvironmentalconditionPackageImpl.init(EnvironmentalconditionPackageImpl.java:1206)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.EnvironmentalconditionPackage.<clinit>(EnvironmentalconditionPackage.java:84)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
at java.lang.reflect.Field.get(Field.java:393)
at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:275)
at org.eclipse.emf.ecore.impl.EPackageRegistryImpl.getEPackage(EPackageRegistryImpl.java:127)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x0a_requestemissionrelateddtcpermanentstatus.impl.Mode_0x0a_requestemissionrelateddtcpermanentstatusPackageImpl.init(Mode_0x0a_requestemissionrelateddtcpermanentstatusPackageImpl.java:1400)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x0a_requestemissionrelateddtcpermanentstatus.Mode_0x0a_requestemissionrelateddtcpermanentstatusPackage.<clinit>(Mode_0x0a_requestemissionrelateddtcpermanentstatusPackage.java:78)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
at java.lang.reflect.Field.get(Field.java:393)
at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:275)
at org.eclipse.emf.ecore.impl.EPackageRegistryImpl.getEPackage(EPackageRegistryImpl.java:127)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x09_requestvehicleinformation.impl.Mode_0x09_requestvehicleinformationPackageImpl.init(Mode_0x09_requestvehicleinformationPackageImpl.java:1399)

idea: ClassNotFoundException

I have the code:
public class GuaranteedDeadlock {
public static void main(String[] args) {
long[] arr = new long[Integer.MAX_VALUE];
}
}
it produces:
Exception in thread "main" java.lang.ClassNotFoundException: GuaranteedDeadlock
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
module settings:
Looks like I configured idea a bit wrong, please correct me.

Newly created JUNIT class not found exception (Class not found com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest)

I created a java file TestNavAssignmentListControllerTest. codes as follows
public class TestNavAssignmentListControllerTest extends
AimswebplusRosterAssesssQueringserverApplicationTests {
#Autowired
private TestnavAssignmentListController testnavAssignmentListController;
#Test
public void searchOk(){
String params = "aimswebId=1168&roster=RCM3MA==&minGrade=0&maxGrade=7&measureCode=&type=&schoolYearVal=2015&benchmarkPeriodId=2&studentsWithNewStatus=0&page=0&size=0&sort=studentName&order=asc&username=manager&assignmentIds=1602,1723,1829,2437";
TestnavAssignmentListDto listDto = (TestnavAssignmentListDto) when().get(BASE_URL + "/query/testnavAssignments?" + params) .as(TestnavAssignmentListDto.class);
assertNotNull(listDto);
}
when I try to run as Junit Test it throws
Class not found com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest
java.lang.ClassNotFoundException: com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
exception.
I worked out with : building the project and compiling the project (using maven)
any one have idea about this please let me know.

Class Not Found Exception When Creating New Instance Of Class Inside of Jar - Java

I am trying to create a new instance of a class to invoke a method in Java. But because the class is inside a jar (Which loads just fine), The class cannot. This causes a ClassNotFoundException to be thrown. Could someone please tell me how to fix this?
Code:
private static void loadClassFromJar(String PluginJar) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
File PluginFile = new File("./debug/plugins/DiamondCorePlugin.jar");
URL[] PluginURLs = { PluginFile.getAbsoluteFile().toURI().toURL() };
URLClassLoader ClassLoader = URLClassLoader.newInstance(PluginURLs);
Class<?> PluginClass = ClassLoader.loadClass("net.trenterprises.diamondcore.plugin.Main");
Method EventMethod = PluginClass.getMethod("onEnable");
EventMethod.invoke(PluginClass.newInstance());
}
Stack trace:
java.lang.ClassNotFoundException: net.trenterprises.diamondcore.plugin.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at net.trenterprises.diamondcore.cross.api.javaplugin.sub.Server.getClassCaller(Server.java:23)
at net.trenterprises.diamondcore.cross.api.javaplugin.sub.Server.getLogger(Server.java:15)
at net.trenterprises.diamondcore.plugin.Main.onEnable(Main.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadClassFromJar(PluginLoader.java:55)
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadAllPlugins(PluginLoader.java:25)
at net.trenterprises.diamondcore.DiamondCoreServer.<init>(DiamondCoreServer.java:47)
at net.trenterprises.diamondcore.run.main(run.java:15)
Found the problem! It turned out that the class was loading just fine, but in another class that tried to get the classes name, becuase the class was in a JAR file. It could not load! Thank you for all of the help immibiz and vanza!

Categories

Resources